yii整合smarty
来源:互联网 发布:薛蟠 知乎 编辑:程序博客网 时间:2024/06/05 22:30
1.在protected下新建extensions,在extensions文件夹,把smarty的libs文件夹下文件考入extensions并改名为smarty
2.在protected下的extensions(Yii的扩展默认都扔到这里)中建立CSmarty类文件。
<?php/** *Author:Elite */require_once(Yii::getPathOfAlias('application.extensions.smarty').DIRECTORY_SEPARATOR.'Smarty.class.php');define('SMARTY_VIEW_DIR', Yii::getPathOfAlias('application.views'));class CSmarty extends Smarty {const DIR_SEP = DIRECTORY_SEPARATOR;function __construct() {parent::__construct(); $this->template_dir = 'http://xxxxxx.cn/';//模版位置可在项目内SMARTY_VIEW_DIR也可以引用项目外$this->compile_dir = SMARTY_VIEW_DIR.self::DIR_SEP.'template_c'; //生成文件存放位置$this->caching = false; //是否需要缓存//$this->cache_dir = SMARTY_VIEW_DIR.self::DIR_SEP.'cache'; //缓存存放位置$this->left_delimiter = '{#';//标签开始$this->right_delimiter = '#}';//标签结束$this->cache_lifetime = 3600;}function init() {Yii::registerAutoloader('smartyAutoload');//如不写 要在相应的文件夹下建立template_c文件夹和cache文件夹}}?>
3.打开protected/config/main.php,在components数组中加入
//smarty'smarty'=>array('class'=>'application.extensions.CSmarty',),
4.最后在action中直接用Yii::app()->smarty就可以试用smarty了。如果每次在action中使用Yii::app()->smarty比较麻烦的话,可以在components下的Controller中可以加入
public function actionTest() {$smarty= Yii::app()->smarty;$mburl='test.html';//模版名$smarty->smarty->assign('content','替换为');$smarty->smarty->display($mburl);}
- yii整合smarty
- 在Yii中整合Smarty
- Yii使用smarty模板
- Zendframework 1.6整合Smarty
- Zend Framework+Smarty 整合
- CodeIgniter整合smarty
- CI 里面整合Smarty
- zendframework2 与 smarty 整合
- ci smarty 整合
- ci smarty 整合
- Codeigniter整合smarty
- Codeigniter轻松整合smarty
- YII2 整合smarty
- CI轻松整合smarty
- Yii1整合smarty
- yii2整合smarty
- yii 整合 ckeditor,ckfinder
- dwz yii 的整合
- Linux与VxWorks主要区别(三):内存访问和内存保护
- replace 替换字符串。
- 数组和指针的区别
- eclipse 打包时包括外部jar
- ubuntu下安装Python的MySql的开发环境
- yii整合smarty
- 视频基本术语
- 了解系统及卡片完成
- 金融的资料
- win7+VS2010/2012+cocos2d-x-V2.1.4 环境安装+使用模板
- 几种常用的视频接口
- Junit - JMock 入门
- Win7环境下VS2010配置Cocos2d-x-2.1.4最新版本的开发环境(亲测)
- Activity之间的数据传递: Intent