在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了。