在protected下的extensions文件夹放入咱们的smarty类包,按照约定咱们同在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 = SMARTY_VIEW_DIR;
- $this->compile_dir = SMARTY_VIEW_DIR.self::DIR_SEP.'template_c';
- $this->caching = true;
- $this->cache_dir = SMARTY_VIEW_DIR.self::DIR_SEP.'cache';
- $this->left_delimiter = '<!--{';
- $this->right_delimiter = '}-->';
- $this->cache_lifetime = 3600;
- }
- function init() {}
- }
- ?>
而后创建相关联的文件夹。app
紧接这是咱们的配置部分ide
打开protected/config/main.php
在components数组中加入this
'smarty'=>array(
),spa
最后在action中直接
protected $smarty = '';get
protected function init() {
$this->smarty = Yii::app()->smarty;
}string
而后在action中直接能够用$this->smarty使用smarty了。