[yii]sae-yii-with-smarty

这里介绍了sae环境安装smarty-view-renderer扩展,亲测有效
一普通环境安装smarty-view-renderer
Yii 拥有smarty的扩展,而且很好用。具体看连接:http://www.yiiframework.com/extension/smarty-view-renderer
安装这个扩展需要三步:
1, 将扩展放在: protected/extensions下
2, 将smarty的lib放在 protected/vendors/Smarty下(smarty3请在官网下载)
3, 添加config的配置

'viewRenderer'=>array(
  'class'=>'application.extensions.yiiext.renderers.smarty.ESmartyViewRenderer',
    'fileExtension' => '.tpl',
    //'pluginsDir' => 'application.smartyPlugins',
    //'configDir' => 'application.smartyConfig',
),

二 根据SAE进行配置
一般的Yii到这里就可以使用了,但是SAE没有写权限,smarty在编译时产生编译文件,所以要将编译文件写在memcache中,但这需要耗费sae的豆!
1,/protected/vendor/Smarty/目录下的Smarty.class.php文件:
防止调用touch,saemc会自动更新时间,不需要touch

public $compile_locking = false;

2, /protected/extensions/ESmartyViewRenderer.php
修改为

    $this->getSmarty()->setTemplateDir('saemc://templates_c/');
$compileDir = isset($this->config['compile_dir']) ?
					  $this->config['compile_dir'] :'saemc://templates_c/';

写入到sae的memcache

三 测试
最后在自己的IndexController测试下:

    public function actionIndex() {
        
         $data = array("name" => "willwcw@163.com");
         $this->render("index", $data);
        
}

Tpl文件

mail:{$name}
this is tpl

如果参数替换成功,表示模板生效。
最后:源码放在github上了,空的框架,没有其他任何配置
https://github.com/wangchunwei/sae-yii-with-smarty

发表评论

电子邮件地址不会被公开。 必填项已用*标注


*