Yii1.1整合smarty模板以及使用
2015-06-18 17:48
881 查看
Yii1.1整合smarty模板
法一:
一,下载smarty3.X到本地,放到Yii框架 /protected/extensions/目录下
这里多余的smarty包里的demo和非重要文件都没有删除。
***要非常注意Smarty.class.php 的位置,这里有对其他php类文件的路径定义变量,如果改变了Smarty.class.php 位置,记得一定要修改该文件中路径变量,否则再引入sysplugins包中的php时 会报:找不到资源的错误!!***
二,在/protected/extensions/目录下创建CSmarty.php文件
<?php
define('SMARTY_SPL_AUTOLOAD', true);
require_once (Yii::getPathOfAlias('application.extensions.smarty').DIRECTORY_SEPARATOR.'libs'.DIRECTORY_SEPARATOR.'Smarty.class.php'); //smarty配置
define('SMARTY_VIEW_DIR', Yii::getPathOfAlias('application.views.sblog.smarty'));
class CSmarty extends Smarty{
public $_smarty;
function __construct() {
parent::__construct();
$this->template_dir = SMARTY_VIEW_DIR.DS.'tpl';
$this->compile_dir = SMARTY_VIEW_DIR.DS.'tpl_c';
$this->caching = false;
$this->cache_dir = SMARTY_VIEW_DIR.DS.'cache';
$this->config_dir = SMARTY_VIEW_DIR.DS.'config';
$this->cache_lifetime = 3600;
}
function init(){
// Yii::registerAutoloader('smartyAutoload');
}
}
?>
注意两点:
1,Smarty.class.php的路径,根据自己的实际情况来写
2,SMARTY_VIEW_DIR 这个是smarty的模板起作用的路径,可以随意指定。
3,DS 是路径分隔符’/’
三,在/protected/config/main.php 文件中加
这样就把smarty整合到Yii1.1里了。
如何使用呢?
一,在/protected/components/Controller.php 文件中,加
public $smarty;
public function init() {
$this->smarty = Yii::app()->smarty;
}
二,在/protected/controllers/XXXController.php中的actionXXX函数中
$world = "lily";
$this->smarty->assign( 'world', $world );
$this->smarty->display( 'test.html');test.html 在smarty模板目录中建立。
法一:
一,下载smarty3.X到本地,放到Yii框架 /protected/extensions/目录下
这里多余的smarty包里的demo和非重要文件都没有删除。
***要非常注意Smarty.class.php 的位置,这里有对其他php类文件的路径定义变量,如果改变了Smarty.class.php 位置,记得一定要修改该文件中路径变量,否则再引入sysplugins包中的php时 会报:找不到资源的错误!!***
二,在/protected/extensions/目录下创建CSmarty.php文件
<?php
define('SMARTY_SPL_AUTOLOAD', true);
require_once (Yii::getPathOfAlias('application.extensions.smarty').DIRECTORY_SEPARATOR.'libs'.DIRECTORY_SEPARATOR.'Smarty.class.php'); //smarty配置
define('SMARTY_VIEW_DIR', Yii::getPathOfAlias('application.views.sblog.smarty'));
class CSmarty extends Smarty{
public $_smarty;
function __construct() {
parent::__construct();
$this->template_dir = SMARTY_VIEW_DIR.DS.'tpl';
$this->compile_dir = SMARTY_VIEW_DIR.DS.'tpl_c';
$this->caching = false;
$this->cache_dir = SMARTY_VIEW_DIR.DS.'cache';
$this->config_dir = SMARTY_VIEW_DIR.DS.'config';
$this->cache_lifetime = 3600;
}
function init(){
// Yii::registerAutoloader('smartyAutoload');
}
}
?>
注意两点:
1,Smarty.class.php的路径,根据自己的实际情况来写
2,SMARTY_VIEW_DIR 这个是smarty的模板起作用的路径,可以随意指定。
3,DS 是路径分隔符’/’
三,在/protected/config/main.php 文件中加
'components'=>array( 'user'=>array( // enable cookie-based authentication 'allowAutoLogin'=>true, ), 'smarty'=>array( 'class'=>'application.extensions.CSmarty', ),
这样就把smarty整合到Yii1.1里了。
如何使用呢?
一,在/protected/components/Controller.php 文件中,加
public $smarty;
public function init() {
$this->smarty = Yii::app()->smarty;
}
二,在/protected/controllers/XXXController.php中的actionXXX函数中
$world = "lily";
$this->smarty->assign( 'world', $world );
$this->smarty->display( 'test.html');test.html 在smarty模板目录中建立。
相关文章推荐
- 2. Laravel5学习笔记:执行route:cache时报LogicException
- php实现比较两个文件夹异同的方法
- php判断两个日期之间相差多少个月份的方法
- php -- php缓存技术
- NTP服务器搭建
- 修改.htaccess执行非php文件
- Laravel-excel安装及使用
- php面向对象基础概念(属性重载的魔术方法)__get(),__set(),__isset(),__unset()
- php实现转换ubb代码的方法
- PHP将Excel另存为html页面
- php实现的日历程序
- PHP中func_get_args(),func_get_arg(),func_num_args()的区别
- [PHP] EDBID:36372中上传漏洞源代码分析
- PHP将数组存入到数据库中
- windows ntp 服务器
- LAMP第三部分php,mysql配置
- php实现的验证码文件类实例
- PHP时间格式大全
- [PHP] 图像二次渲染
- 【PHP定时执行计划任务】