PHP

浏览模式: 标准 | 列表 | 图文
值得收藏的yii2的doc中关于db Query的说明

值得收藏的yii2的doc中关于db Query的说明

Yii2的DB操作与1有很大的区别。所以下面这段还是值得收藏的
虽然第一句让我很简单,但没关系,大部分内容还是照用的,原文地址来自:https://github.com/yiisoft/yii2/blob/master/docs/guide/db-query-builder.md
为什么就没有cdbcriteria了呢?哎。。。

Note: This section is under development.

Yii provides a basic database access layer as described in the Database basics section. The database access layer provides a low-level way to interact with the database. While useful in some situations, it can be tedious and error-prone to write raw SQLs. An alternative approach is to use the Query Builder. The Query Builder provides an object-oriented vehicle for generating queries to be executed.

A typical usage of the query builder looks like the following:

$rows = (new \yii\db\Query())     ->select('id, name')     ->from('user')     ->limit(10)     ->all();  // which is equivalent to the following code:  $query = (new \yii\db\Query())     ->select('id, name')     ->from('user')     ->limit(10);  // Create a command. You can get the actual SQL using $command->sql $command = $query->createCommand();  // Execute the command: $rows = $command->queryAll();

Query Methods

As you can see, [[yii\db\Query]] is the main player that you need to deal with. Behind the scene, Query is actually only responsible for representing various query information. The actual query building logic is done by [[yii\db\QueryBuilder]] when you call the createCommand() method, and the query execution is done by [[yii\db\Command]].

For convenience, [[yii\db\Query]] provides a set of commonly used query methods that will build the query, execute it, and return the result. For example,

  • [[yii\db\Query::all()|all()]]: builds the query, executes it and returns all results as an array.
  • [[yii\db\Query::one()|one()]]: returns the first row of the result.
  • [[yii\db\Query::column()|column()]]: returns the first column of the result.
  • [[yii\db\Query::scalar()|scalar()]]: returns the first column in the first row of the result.
  • [[yii\db\Query::exists()|exists()]]: returns a value indicating whether the query results in anything.
  • [[yii\db\Query::count()|count()]]: returns the result of a COUNT query. Other similar methods include sum($q),average($q), max($q), min($q), which support the so-called aggregational data query. $q parameter is mandatory for these methods and can be either the column name or expression.

Building Query

In the following, we will explain how to build various clauses in a SQL statement. For simplicity, we use $query to represent a [[yii\db\Query]] object.

SELECT

In order to form a basic SELECT query, you need to specify what columns to select and from what table:

$query->select('id, name')     ->from('user');

Select options can be specified as a comma-separated string, as in the above, or as an array. The array syntax is especially useful when forming the selection dynamically:

$query->select(['id', 'name'])     ->from('user');

Info: You should always use the array format if your SELECT clause contains SQL expressions. This is because a SQL expression like CONCAT(first_name, last_name) AS full_name may contain commas. If you list it together with other columns in a string, the expression may be split into several parts by commas, which is not what you want to see.

When specifying columns, you may include the table prefixes or column aliases, e.g., user.id, user.id AS user_id. If you are using array to specify the columns, you may also use the array keys to specify the column aliases, e.g.,['user_id' => 'user.id', 'user_name' => 'user.name'].

Starting from version 2.0.1, you may also select sub-queries as columns. For example,

$subQuery = (new Query)->select('COUNT(*)')->from('user'); $query = (new Query)->select(['id', 'count' => $subQuery])->from('post'); // $query represents the following SQL: // SELECT `id`, (SELECT COUNT(*) FROM `user`) AS `count` FROM `post`

To select distinct rows, you may call distinct(), like the following:

$query->select('user_id')->distinct()->from('post');

FROM

To specify which table(s) to select data from, call from():

$query->select('*')->from('user');

You may specify multiple tables using a comma-separated string or an array. Table names can contain schema prefixes (e.g. 'public.user') and/or table aliases (e.g. 'user u'). The method will automatically quote the table names unless it contains some parenthesis (which means the table is given as a sub-query or DB expression). For example,

$query->select('u.*, p.*')->from(['user u', 'post p']);

When the tables are specified as an array, you may also use the array keys as the table aliases (if a table does not need alias, do not use a string key). For example,

$query->select('u.*, p.*')->from(['u' => 'user', 'p' => 'post']);

You may specify a sub-query using a Query object. In this case, the corresponding array key will be used as the alias for the sub-query.

$subQuery = (new Query())->select('id')->from('user')->where('status=1'); $query->select('*')->from(['u' => $subQuery]);

WHERE

Usually data is selected based upon certain criteria. Query Builder has some useful methods to specify these, the most powerful of which being where. It can be used in multiple ways.

The simplest way to apply a condition is to use a string:

$query->where('status=:status', [':status' => $status]);

When using strings, make sure you're binding the query parameters, not creating a query by string concatenation. The above approach is safe to use, the following is not:

$query->where("status=$status"); // Dangerous!

Instead of binding the status value immediately, you can do so using params or addParams:

$query->where('status=:status'); $query->addParams([':status' => $status]);

Multiple conditions can simultaneously be set in where using the hash format:

$query->where([     'status' => 10,     'type' => 2,     'id' => [4, 8, 15, 16, 23, 42], ]);

That code will generate the following SQL:

WHERE (`status` = 10) AND (`type` = 2) AND (`id` IN (4, 8, 15, 16, 23, 42))

NULL is a special value in databases, and is handled smartly by the Query Builder. This code:

$query->where(['status' => null]);

results in this WHERE clause:

WHERE (`status` IS NULL)

You can also create sub-queries with Query objects like the following,

$userQuery = (new Query)->select('id')->from('user'); $query->where(['id' => $userQuery]);

which will generate the following SQL:

WHERE `id` IN (SELECT `id` FROM `user`)

Another way to use the method is the operand format which is [operator, operand1, operand2, ...].

Operator can be one of the following (see also [[yii\db\QueryInterface::where()]]):

  • and: the operands should be concatenated together using AND. For example, ['and', 'id=1', 'id=2'] will generate id=1 AND id=2. If an operand is an array, it will be converted into a string using the rules described here. For example, ['and', 'type=1', ['or', 'id=1', 'id=2']] will generate type=1 AND (id=1 OR id=2). The method will NOT do any quoting or escaping.

  • or: similar to the and operator except that the operands are concatenated using OR.

  • between: operand 1 should be the column name, and operand 2 and 3 should be the starting and ending values of the range that the column is in. For example, ['between', 'id', 1, 10] will generate id BETWEEN 1 AND 10.

  • not between: similar to between except the BETWEEN is replaced with NOT BETWEEN in the generated condition.

  • in: operand 1 should be a column or DB expression. Operand 2 can be either an array or a Query object. It will generate an IN condition. If Operand 2 is an array, it will represent the range of the values that the column or DB expression should be; If Operand 2 is a Query object, a sub-query will be generated and used as the range of the column or DB expression. For example, ['in', 'id', [1, 2, 3]] will generate id IN (1, 2, 3). The method will properly quote the column name and escape values in the range. The in operator also supports composite columns. In this case, operand 1 should be an array of the columns, while operand 2 should be an array of arrays or a Query object representing the range of the columns.

  • not in: similar to the in operator except that IN is replaced with NOT IN in the generated condition.

  • like: operand 1 should be a column or DB expression, and operand 2 be a string or an array representing the values that the column or DB expression should be like. For example, ['like', 'name', 'tester'] will generatename LIKE '%tester%'. When the value range is given as an array, multiple LIKE predicates will be generated and concatenated using AND. For example, ['like', 'name', ['test', 'sample']] will generate name LIKE '%test%' AND name LIKE '%sample%'. You may also provide an optional third operand to specify how to escape special characters in the values. The operand should be an array of mappings from the special characters to their escaped counterparts. If this operand is not provided, a default escape mapping will be used. You may use falseor an empty array to indicate the values are already escaped and no escape should be applied. Note that when using an escape mapping (or the third operand is not provided), the values will be automatically enclosed within a pair of percentage characters.

    Note: When using PostgreSQL you may also use ilike instead of like for case-insensitive matching.

  • or like: similar to the like operator except that OR is used to concatenate the LIKE predicates when operand 2 is an array.

  • not like: similar to the like operator except that LIKE is replaced with NOT LIKE in the generated condition.

  • or not like: similar to the not like operator except that OR is used to concatenate the NOT LIKE predicates.

  • exists: requires one operand which must be an instance of [[yii\db\Query]] representing the sub-query. It will build a EXISTS (sub-query) expression.

  • not exists: similar to the exists operator and builds a NOT EXISTS (sub-query) expression.

Additionally you can specify anything as operator:

$query->select('id')     ->from('user')     ->where(['>=', 'id', 10]);

It will result in:

SELECT id FROM user WHERE id >= 10;

If you are building parts of condition dynamically it's very convenient to use andWhere() and orWhere():

$status = 10; $search = 'yii';  $query->where(['status' => $status]); if (!empty($search)) {     $query->andWhere(['like', 'title', $search]); }

In case $search isn't empty the following SQL will be generated:

WHERE (`status` = 10) AND (`title` LIKE '%yii%')

Building Filter Conditions

When building filter conditions based on user inputs, you usually want to specially handle "empty inputs" by ignoring them in the filters. For example, you have an HTML form that takes username and email inputs. If the user only enters something in the username input, you may want to build a query that only tries to match the entered username. You may use the filterWhere() method to achieve this goal:

// $username and $email are from user inputs $query->filterWhere([     'username' => $username,     'email' => $email, ]);

The filterWhere() method is very similar to where(). The main difference is that filterWhere() will remove empty values from the provided condition. So if $email is "empty", the resulting query will be ...WHERE username=:username; and if both $username and $email are "empty", the query will have no WHERE part.

A value is empty if it is null, an empty string, a string consisting of whitespaces, or an empty array.

You may also use andFilterWhere() and orFilterWhere() to append more filter conditions.

ORDER BY

For ordering results orderBy and addOrderBy could be used:

$query->orderBy([     'id' => SORT_ASC,     'name' => SORT_DESC, ]);

Here we are ordering by id ascending and then by name descending.

GROUP BY and HAVING

In order to add GROUP BY to generated SQL you can use the following:

$query->groupBy('id, status');

If you want to add another field after using groupBy:

$query->addGroupBy(['created_at', 'updated_at']);

To add a HAVING condition the corresponding having method and its andHaving and orHaving can be used. Parameters for these are similar to the ones for where methods group:

$query->having(['status' => $status]);

LIMIT and OFFSET

To limit result to 10 rows limit can be used:

$query->limit(10);

To skip 100 fist rows use:

$query->offset(100);

JOIN

The JOIN clauses are generated in the Query Builder by using the applicable join method:

  • innerJoin()
  • leftJoin()
  • rightJoin()

This left join selects data from two related tables in one query:

$query->select(['user.name AS author', 'post.title as title'])     ->from('user')     ->leftJoin('post', 'post.user_id = user.id');

In the code, the leftJoin() method's first parameter specifies the table to join to. The second parameter defines the join condition.

If your database application supports other join types, you can use those via the generic join method:

$query->join('FULL OUTER JOIN', 'post', 'post.user_id = user.id');

The first argument is the join type to perform. The second is the table to join to, and the third is the condition.

Like FROM, you may also join with sub-queries. To do so, specify the sub-query as an array which must contain one element. The array value must be a Query object representing the sub-query, while the array key is the alias for the sub-query. For example,

$query->leftJoin(['u' => $subQuery], 'u.id=author_id');

UNION

UNION in SQL adds results of one query to results of another query. Columns returned by both queries should match. In Yii in order to build it you can first form two query objects and then use union method:

$query = new Query(); $query->select("id, category_id as type, name")->from('post')->limit(10);  $anotherQuery = new Query(); $anotherQuery->select('id, type, name')->from('user')->limit(10);  $query->union($anotherQuery);

Batch Query

When working with large amount of data, methods such as [[yii\db\Query::all()]] are not suitable because they require loading all data into the memory. To keep the memory requirement low, Yii provides the so-called batch query support. A batch query makes uses of data cursor and fetches data in batches.

Batch query can be used like the following:

use yii\db\Query;  $query = (new Query())     ->from('user')     ->orderBy('id');  foreach ($query->batch() as $users) {     // $users is an array of 100 or fewer rows from the user table }  // or if you want to iterate the row one by one foreach ($query->each() as $user) {     // $user represents one row of data from the user table }

The method [[yii\db\Query::batch()]] and [[yii\db\Query::each()]] return an [[yii\db\BatchQueryResult]] object which implements the Iterator interface and thus can be used in the foreach construct. During the first iteration, a SQL query is made to the database. Data are since then fetched in batches in the iterations. By default, the batch size is 100, meaning 100 rows of data are being fetched in each batch. You can change the batch size by passing the first parameter to the batch() or each() method.

Compared to the [[yii\db\Query::all()]], the batch query only loads 100 rows of data at a time into the memory. If you process the data and then discard it right away, the batch query can help keep the memory usage under a limit.

If you specify the query result to be indexed by some column via [[yii\db\Query::indexBy()]], the batch query will still keep the proper index. For example,

use yii\db\Query;  $query = (new Query())     ->from('user')     ->indexBy('username');  foreach ($query->batch() as $users) {     // $users is indexed by the "username" column }  foreach ($query->each() as $username => $user) { }
Yii2 Html组件的默认值

Yii2 Html组件的默认值

Yii2 的Html组件越来越觉得容易用了。而且也更方便了,不过设置默认值的时候有一点不方便。比如input的时候都是直接设置placeholder就行了

在Yii1的时候,有一个参数 :htmlOptions => array() , 在Yii2中简化到就剩一个options。。。当然 placeholder 还是可以直接用的

只是在dropdownlist的时候,placeholder就不能用了。这时候的参数是:prompt

例子:

$form->field($model, 'lists')->dropDownList(Categories::findAll([1=>1]), ['prompt' => '请选择分类')])

看到那个findAll([1=>1])没。如果只是用默认的findAll,没有条件的话。不能查询,所以只有1=>1这样。

Yii2-smarty的一些小坑

Yii2-smarty的一些小坑

在写本文前我不得不说一句,其实我是不想用smarty的,我想尝试一下twig,但是phpstorm的Twig插件真要命,卡成翔,所以我只能用smarty。为什么不用prado了呢?官方说不支持了,我晶啊

在使用smarty的时候官方的代码和例子看上去很美,不过要注意几点

1、用yii2-smarty,还是必须得用layout,如果你不支持layout文件,默认就是/layouts/main.php,天啊,为什么是PHP?而且在这里面也还真的能用PHP代码。整个都崩溃了

2、你可以指定layout文件,比如:main.tpl,OK你必须得象PHP文件一样,得写{$this->head()},{$this->startBody()}{$this->endPage()}等,否则 ClientScript功能就无法使用

3、如果你指定layout=false,那么,就不支持ClientScript了。因为你incude file='xxx.tpl',在每一个独立的文件里都必须要象2中一个个的this->head(),this->endPage全写上

4、再来一个bug:{registerJsFile url=''},这个函数有BUG

原来是:

public function functionRegisterJsFile($params, $template)
{
if (!isset($params['url'])) {
trigger_error("registerJsFile: missing 'url' parameter");
}

$url = ArrayHelper::remove($params, 'url');
$key = ArrayHelper::remove($params, 'key', null);
$depends = ArrayHelper::remove($params, 'depends', null);
if (isset($params['position']))
$params['position'] = $this->getViewConstVal($params['position'], View::POS_END);

Yii::$app->getView()->registerJsFile($url, $depends, $params, $key);
}

改成为:

/**
* Smarty function plugin
* Usage is the following:
*
* {registerJsFile url='http://maps.google.com/maps/api/js?sensor=false' position='POS_END'}
*
* Supported attributes: url, key, depends, position and valid HTML attributes for the script tag.
* Refer to Yii documentation for details.
* The position attribute is passed as text without the class prefix.
* Default is 'POS_END'.
*
* @param $params
* @param \Smarty_Internal_Template $template
* @return string
* @note Even though this method is public it should not be called directly.
*/
public function functionRegisterJsFile($params, $template)
{
if (!isset($params['url'])) {
trigger_error("registerJsFile: missing 'url' parameter");
}

$url = ArrayHelper::remove($params, 'url');
$key = ArrayHelper::remove($params, 'key', null);
$params['depends'] = ArrayHelper::remove($params, 'depends', null);
if (isset($params['position']))
$params['position'] = $this->getViewConstVal($params['position'], View::POS_END);

Yii::$app->getView()->registerJsFile($url, $params, $key);
}

其实就是$params['depends']这个参数。registerJsFile只能接受3个参数,但事实上用了4个参数,所以调整一下即可

yii 自动加载其他类

Yii2在项目中使用了composer来管理第三方的类库,Yii呢?就没有这样的目录了。不过在他自己的目录结构里其实有这样目录结构,比如extensions。而且默认是用Yii::import("ext.xxxxx.*");来加载

如果再建一个vendor的目录呢?如果我也要用composer怎么办 呢?Yii的加载是靠类名自动加载的。而它的类名却没有办法认到Vendor目录下的程序。这时候应该怎么办呢?

所以Yii还提供了一个简单的办法:Yii::registerAutoloader(array('Requests', 'autoloader'));

看到这个Requests了没,这个就是第三方的HTTP类库,官网是:http://requests.ryanmccue.info/,这应该是目前PHP中最好的Request的类库了,但默认,它的autoload方式,Yii不支持,所以在Requests.php的第一行加入上面的代码。这回好了,Yii::import("ext.Requests"); 你就可以在任何地方调用:Requests::get($url),而不用担心找不到类了

120fc120ecdae99829257bf53973fad0

连接mq出现2538、2539错误

最近在一个合作项目中需要连接ibm的websphere,经常连着连着就报错了。

比如2533错误:Reason:2033 Text:No message available. 没信息了。。。。

再比如2538错误:Connx CompCode:2 Reason:2538 Text:An MQCONN call was issued from a client to connect to a queue manager but the attempt to allocate a conversation to the remote system failed

这2538就是TMD连接不上服务器,后来问了对方,原来,对方挂了。我晕

今天又是2538,再一问,我靠,换IP了。。真受不了

然后改好IP,再连接,结果。。。2539出现了:Reason:2539 Text:An MQCONN call was issued from a client to connect to a queue manager but the attempt to establish communication failed

查了下2539对应的错误:

2539 (09EB) (RC2539): MQRC_CHANNEL_CONFIG_ERROR

Explanation

An MQCONN call was issued from a client to connect to a queue manager but the attempt to establish communication failed. Common causes of this reason code are:

a.The server and client cannot agree on the channel attributes to use.
b.There are errors in one or both of the QM.INI or MQCLIENT.INI configuration files.
c.The server machine does not support the code page used by the client.

有三种可能。。。现在就等对方折腾了。不过查了下,关于第三种,code page不一样的错误,在http://www.cnblogs.com/fromchaos/archive/2010/02/24/1672736.html,有个解释。为了方便我就复制部分东西过来了

选择客户机或服务器编码字符集标识(CCSID)

客户机代码假设通过客户机中 MQI 的字符数据位于机器所配置的 CCSID 中。如果此 CCSID 是一个不支持的 CCSID 或不是必需的 CCSID,可以用 MQCCSID 环境变量覆盖它,例如,在 Windows® 上:

SET MQCCSID=850
更新开始或者,在 UNIX® 系统上:
export MQCCSID=850

如果是CCSID的问题我只要加在rc.local就好了,不过目前还不知道对方是不是这个错误。。。最后再转一下上述文章的最后一段,关于CCSID的说明

IBM Coded Character Set Identifiers (CCSID)码表

A CCSID is a Coded Character Set Identifier. The Unicode standard defines a Coded Character Set as "A character set in which each character is assigned a numeric code value." This means that a CCSID is a number that defines a numeric ordering of characters. The IBM ® Character Data Representation Architecture (CDRA) as defined in SC09-1390, defines CCSIDs that are used with IBM to represent character data. This architecture defines Single Byte Character Set (SBCS) CCSIDs, Multiple Byte Character Set (MBCS) CCSIDs, and Mixed CCSIDs which are a combination of SBCS and MBCS data. MBCS CCSIDs are usually used for languages, such as Chinese, Japanese, and Korean, that define a larger number of characters than can be represented in a single byte.
CCSID是一个字符集的标识。作为unicode标准通过定义一个字符集内每个字符要对应那个数字值的方式定义了一个字符集。这说明CCSID就是一个定义字符集顺序的标识数码罢了。IBM的字符标识架构在文档 SC09-1390(http://www-304.ibm.com/jct03002c/software/globalization/cdra/index.jsp;http://publib.boulder.ibm.com/cgi-bin/bookmgr/BOOKS/FOCREF00/CCONTENTS)中做了定义,CCSID是IBM用来标识字符序列的标识代码。这个架构定义了SDCS(单字符集)的CCSID值,MBCS(多字符集)的CCSID值和混合单字符多字符集的混合CCSID值。多字符集的CCSID一般用于语言,比如中文,日文,韩文,这些语言的字符量很大,无法用单字节的码值来代表。

All SBCS CCSIDs define a similar basic set of characters, although they might define them in different numeric ordering. For instance all SBCS EBCDIC CCSIDs define the number "1" as x'F0' and all SBCS ASCII CCSIDs define the number 1 as x'30'.

CCSID间的转换有多种类型。其中一种转换就是从一种CCSID到另一种CCSID的转换,举例来说从ASCII(CCSID 1252)到EBCDIC(CCSID 37)。另一种是从串数据到另一种数据类型的转换。举例来说转换字符串数据到数值。在所有的这种类型的转换中都必须标识CCSID值来保证转换的正确进行。

但是转换是有要求的,第一种转换的前提是转到的 CCSID的类型中要包含转换前的CCSID类型中要转换的字符,比如,如果从CCSID1381(S-CHGBPC-DATA) 类型的简体中文的PC编码中的一个中文字符"中"字到其他CCSID编码转换到的编码起码要求这个CCSID编码的字符集中包含同样的"中"字。

我从IBM找到的对CCSID说明的列表如下:

摘录自http://www-304.ibm.com/jct03002c/software/globalization/ccsid/ccsid_registered.jsp,如果需要详细信息,请自行查询。

做个笔记,从去年开始,不停的在与第三方对接程序。有时候真心想骂娘,后来想想,大家都是混口饭吃嘛。而且人家还是上游单位,混的比你好多了。。不要与他们一般见识 。

e986f470c668c8732b7d7c519a5eb60d

d9a883526439d4ec2c8f18cb38f4ad4d

typecho Stat 插件的小BUG

typecho Stat 插件的小BUG

在使用Stat插件时,发现代码中存在一个小BUG,是对Columns not found的判断有问题,原代码写的是:

'Mysql' == $type && 1051 == $code

但事实上,如果你使用的是PDO,$code 还应该加上 42S22,所以上述代码就应该改成这样了

('Mysql' == $type && (1054 == $code || $code == '42S22'))

然后就可以安装成功了。

该插件的信息是:

/**
* 页面浏览次数统计插件
* @package Stat
* @author Hanny
* @version 1.0.2
* @dependence 10.8.15-*
* @link http://www.imhan.com
* 历史版本
* version 1.0.2 at 2010-07-03
* 终于支持前台调用了
* 接口支持Typecho 0.8的计数
* 增加SQLite的支持
* version 1.0.1 at 2010-01-02
* 修改安装出错处理
* 修改安装时默认值错误
* version 1.0.0 at 2009-12-12
* 实现浏览次数统计的基本功能

*/

不过由于这个版本比较早,就将就一下啦

让人吃药的max_input_vars

让人吃药的max_input_vars

在某个项目中,每次提交都丢了部分数据,觉得非常奇怪,开始的时候以为是数据量过大,但后来又觉得不应该,因为如果是数据量过大,要么就是提交失败,要么就是直接报错啊?

但事实上我每次提交都是成功的,但print_r($_POST)的时候,总丢了不少的数据,这是为什么呢?

于是,将http头中的form内容全部copy出来,查看了一下,发现共是1200多行。打印POST的时候,只有1000行,咦,这不科学啊?少了200多行?

google了一下,原来,PHP有这么一个配置:

; How many GET/POST/COOKIE input variables may be accepted
; max_input_vars = 1000

而它的默认值 是1000,好吧,如果不是这次意外,根本不会发现项目中存在的这个BUG,毕竟要提交1000多个参数还是有难度的。顺便说一下:param[]=1&param[]=2是属于两个参数。所以如果你提交的项目中有多个数组,每个数组又有不少值的话,你就真的要小心了

手贱,将max_input_vars 改成5000,问题解决。。

------

回顾,这种因为偷懒的事情往往出现在哪里呢?

1、ajax提交,不管三七二十一,将某堆数据 serializeArray(),jquery的这个功能,偶尔真心会让人吃药。

2、日程管理和广告排期管理,这时候input的key确实 有可能会超过1000,但我还是建议先序列化再存到一个字段提交更安心 吧?

------
OVER

thinkphp模板中的Load好象有BUG

thinkphp模板中的Load好象有BUG

在thinkPHP的模板中,有几个tag标签都是用来引入js和css的,比如:import/css/js/load之类的,经过测试,好象load这个Tag有BUG

比如:<load href="/assets/static/wap/css/reset.css"/>,加载一个CSS文件,这个没问题,但如果使用<load href="/assets/static/wap/css/reset.css?ver=1"/>,这种就直接失效了。

当然如果你使用<css file="xxxx?ver=1" />是有效的

看了下代码,好象在没有明确标记类型的时候,程序判断后缀名失效了。<css>标签是主动告诉import程序,我的类型是css,而load是根据代码判断的,因此,对于load应该主动加上type="css",或者,修改程序:

120fc120ecdae99829257bf53973fad0

看划线的地方,这里应该先basename,把?或者其他带有版本的信息先去除干净才OK。

或许这是一个bug,或许,就是提示你应该主动加类型。

如何解决wordpress后台打开超慢的总是

如何解决wordpress后台打开超慢的总是

最近有些朋友和我说,wordpress的后台在本地打开都超慢。不知道为什么,负载什么的都没有。

看了下代码,同时也看了下网络上的评论,原来最近大家都喜欢上了使用google的字体,众所周知,google的各种服务在国内访问都是渣渣,真不知道怎么会有这样的公司,明明这个网站就打不开,还有那么多人用它的东西。当然你懂的
既然知道问题在哪里就好办了。
1、插件法
现在针对上述情况,国内开发人员已经开发了相应的插件来处理了,如disable google fonts或者其他的,你搜索google fonts就可以
2、代码法
在wp-include/script-loader.php中,你会找到font.googleapis.com的字样。你只要替换掉它们即可(当然,删除也可以),如果你有需要用这些字体,你可以用数字公司提供的前端CDN库(http://libs.useso.com/)。到了上述的网址我相信你也应该知道怎么了。
不知道何时才能打开那些网站,这些就当成技巧先保留着吧
被两个问题搞死。。

被两个问题搞死。。

今天被两个问题搞死

1、加载hprose.phar/HproseHttpServer.php一直报文件找不到:Warning: include(./hprose.phar/HproseHttpServer.php): failed to open stream: No such file or directory
2、定义了Yii的errorHandler和error的Controller结果死活不对。
解决:
1、居然是忘了phar在include的时候要申明协议,即include('hprose.phar/xxx.php')是不对的。必须要include("phar://hprose.phar/xxx.php");
该死的,居然忘了这个,命令行下写代码,总是搞错东西
2、这个问题说实在的。真TMD操蛋,我是想偷懒的,所以就加载了yiit.php。。想着这是个lite的文件,应该没啥问题啊?结果,就是因为加载的yiit.php而不是yii.php搞得我在那里折腾了半天。真是要人命啊
果然就象老王说的,每一个找寻半天不得结果的BUG后面,都有一个令人啼笑皆非的原因