Submitted by gouki on 2014, November 20, 4:22 PM
在写本文前我不得不说一句,其实我是不想用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
原来是:
PHP代码
- 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);
- }
改成为:
PHP代码
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 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个参数,所以调整一下即可
Tags: yii2, smarty, twig
PHP | 评论:0
| 阅读:26239
Submitted by gouki on 2014, October 16, 11:32 PM
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),而不用担心找不到类了
PHP | 评论:2
| 阅读:18983
Submitted by gouki on 2014, October 13, 2:49 PM
Yii2 终于released了。发现他的advanced的目录和我现在完全一致。哈哈。。。
不过在测试的时候遇到了这个问题:
XML/HTML代码
- composer install
- Loading composer repositories with package information
- Installing dependencies (including require-dev)
- Your requirements could not be resolved to an installable set of packages.
-
- Problem 1
- - Installation request for yiisoft/yii2 * -> satisfiable by yiisoft/yii2[2.0.0].
- - yiisoft/yii2 2.0.0 requires bower-asset/jquery 2.1.*@stable | 1.11.*@stable -> no matching package found.
- Problem 2
- - Installation request for yiisoft/yii2-bootstrap * -> satisfiable by yiisoft/yii2-bootstrap[2.0.0].
- - yiisoft/yii2-bootstrap 2.0.0 requires bower-asset/bootstrap 3.2.* | 3.1.* -> no matching package found.
- Problem 3
- - Installation request for yiisoft/yii2-gii * -> satisfiable by yiisoft/yii2-gii[2.0.0].
- - yiisoft/yii2-gii 2.0.0 requires bower-asset/typeahead.js 0.10.* -> no matching package found.
- Problem 4
- - yiisoft/yii2 2.0.0 requires bower-asset/jquery 2.1.*@stable | 1.11.*@stable -> no matching package found.
- - yiisoft/yii2-faker 2.0.0 requires yiisoft/yii2 * -> satisfiable by yiisoft/yii2[2.0.0].
- - Installation request for yiisoft/yii2-faker * -> satisfiable by yiisoft/yii2-faker[2.0.0].
-
- Potential causes:
- - A typo in the package name
- - The package is not available in a stable-enough version according to your minimum-stability setting
- see <https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion> for more details.
-
- Read <http://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.
这不是什么大问题,只是安装不上罢了。问题出来哪里呢?看了一下官方的issue,有对它的解释:https://github.com/composer/composer/issues/2873
毕竟,虽然yii2是stable了,但不是所有关联的项目都是stable了。把项目中的:"minimum-stability":"stable"改成 "minimum-stability":"dev"即可
于是:composer install
Loading composer repositories with package information
Installing dependencies (including require-dev)
- Installing yiisoft/yii2-composer (dev-master 73ad236)
Cloning 73ad236be1bf7cf4415559a4b592dd5b9cb4b288
-------EOF。
PHP | 评论:0
| 阅读:21244
Submitted by gouki on 2014, October 11, 3:44 PM
最近在一个合作项目中需要连接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对应的错误:
XML/HTML代码
- 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,有个解释。为了方便我就复制部分东西过来了
XML/HTML代码
- 选择客户机或服务器编码字符集标识(CCSID)
-
- 客户机代码假设通过客户机中 MQI 的字符数据位于机器所配置的 CCSID 中。如果此 CCSID 是一个不支持的 CCSID 或不是必需的 CCSID,可以用 MQCCSID 环境变量覆盖它,例如,在 Windows® 上:
-
- SET MQCCSID=850
- 更新开始或者,在 UNIX® 系统上:
- export MQCCSID=850
如果是CCSID的问题我只要加在rc.local就好了,不过目前还不知道对方是不是这个错误。。。最后再转一下上述文章的最后一段,关于CCSID的说明
XML/HTML代码
- 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,如果需要详细信息,请自行查询。
做个笔记,从去年开始,不停的在与第三方对接程序。有时候真心想骂娘,后来想想,大家都是混口饭吃嘛。而且人家还是上游单位,混的比你好多了。。不要与他们一般见识 。
Tags: websphere
PHP | 评论:0
| 阅读:29360
Submitted by gouki on 2014, September 11, 11:24 PM
在使用Stat插件时,发现代码中存在一个小BUG,是对Columns not found的判断有问题,原代码写的是:
XML/HTML代码
- 'Mysql' == $type && 1051 == $code
但事实上,如果你使用的是PDO,$code 还应该加上 42S22,所以上述代码就应该改成这样了
PHP代码
- ('Mysql' == $type && (1054 == $code || $code == '42S22'))
然后就可以安装成功了。
该插件的信息是:
XML/HTML代码
- /**
- * 页面浏览次数统计插件
- * @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
- * 实现浏览次数统计的基本功能
-
- */
不过由于这个版本比较早,就将就一下啦
PHP | 评论:1
| 阅读:18663