2014 年 11 月

浏览模式: 标准 | 列表 | 图文
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个参数,所以调整一下即可

怎样删除vmware fusion

怎样删除vmware fusion

早些年用vmware fusion的时候,就感觉速度不行。总是觉得卡卡顿顿的,后来用了pd后才发现,真心不是一个量级的

vmware我分配了2G内存,才跑起来不卡,我用PD,512M都能飞一样的。

但早期我删除的vmware的时候,是直接把vmware fusion.app拖到垃圾筒里了,结果。它的虚拟网卡还在,这让我很烦恼,如今,有一个比较方便的方法:

rm -rf /Library/Application\ Support/VMware/
rm -rf /Library/Preferences/VMware\ Fusion
rm -rf ~/Library/Application\ Support/VMware\ Fusion
rm -rf ~/Library/Caches/com.vmware.fusion
rm -rf ~/Library/Preferences/VMware\ Fusion
rm -rf ~/Library/Preferences/com.vmware.fusion.LSSharedFileList.plist
rm -rf ~/Library/Preferences/com.vmware.fusion.LSSharedFileList.plist.lockfile
rm -rf ~/Library/Preferences/com.vmware.fusion.plist
rm -rf ~/Library/Preferences/com.vmware.fusion.plist.lockfile
rm -rf ~/Library/Preferences/com.vmware.fusionDaemon.plist
rm -rf ~/Library/Preferences/com.vmware.fusionDaemon.plist.lockfile
rm -rf ~/Library/Preferences/com.vmware.fusionStartMenu.plist
rm -rf ~/Library/Preferences/com.vmware.fusionStartMenu.plist.lockfile

运行之前,记得先sudo -s 进入管理员模式。

上面的数据不是我平空捏造,它来自官方:http://kb.vmware.com/selfservice/microsites/search.do?cmd=displayKC&docType=kc&docTypeID=DT_KB_1_1&externalId=1017838

同时,该文里还有手动删除 3.x的办法,我想,现在2014年应该没有3.x的用户了吧?

wget与wput

wget与wput

不多写,就几个关键点:

wget ftp://xxx.xxx.xxxx.xxx/data/* --ftp-user=xxx --ftp-password=xxx
用于下载FTP目录
wput /var/www/xxxx ftp://user@password:/data/xxxx
上传目录,但上传的时候会有点小问题,比如有中文、或者有空格的时候,在批量上传的时候可能会失败
据说:
$find /home/test -type f >> ~/list.txt
$while read i ; do wput “$i” ftp://ftpusername:password@ip/myname ; done < ~/list.txt
未测试,但看这个while do 应该可行。
纯笔记
最后附上wget拉取整站的代码:
wget \
--recursive \
--no-clobber \
--page-requisites \
--html-extension \
--convert-links \
--restrict-file-names=windows \
--domains example.com \
--no-parent \
www.example.com/article/page/
可以参考一下不过对于CSS嵌套CSS中的图片可能不OK