CodeIgniter中使用Smarty3基本配置
《CodeIgniter中使用Smarty3基本配置》要点: PHP应用一、创立Smarty类库 1.将smarty的libs文件复制到libraries下(这里我重命名为smarty) PHP利用Cismarty.php <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); require(APPPATH . 'libraries/smarty/Smarty.class.php'); //CI,文件系统全用相对路径相对index.php所在的路径,url全部用绝对路径. //BASEPATH - The full server path to the "system" folder //APPPATH - The full server path to the "application" folder class Cismarty extends Smarty { public function __construct() { parent::__construct(); $this->caching = false; $this->setTemplateDir(APPPATH . 'views/Smarty/templates'); //设定所有模板文件都必要放置的目录地址. $this->setConfigDir(APPPATH . 'views/Smarty/configs'); //设定用于存放模板特殊配置文件的目录,$this->setCacheDir(APPPATH . 'views/Smarty/cache'); //在启动缓存特性的情况下,这个属性所指定的目录中放置Smarty缓存的所有模板 $this->setPluginsDir(APPPATH . 'views/Smarty/plugins'); //插件目录 $this->setCompileDir(APPPATH . 'views/Smarty/templates_c'); //设定Smarty编译过的所有模板文件的存放目录地址 } } ?> ?在对应目录新建smarty的文件夹.templates,configs,cache,plugins,templates_c. 二、节制器文件 建立控制器文件paper.php(类名的首字母大写)(使用load加载libraries时默认执行构造器函数,使用url路由拜访控制器时执行构造器函数和默认的index方法.) PHP利用
<?php
class Paper extends CI_Controller
{
function __construct()
{
parent::__construct();
}
public function pri_body()
{
$this->load->library('cismarty');
$this->cismarty->assign("name",1200);
$this->cismarty->display('dd.tpl');
}
}
?>
PHP利用?也可以在application/config/autoload.php中配置自动加载资源. 《CodeIgniter中使用Smarty3基本配置》是否对您有启发,欢迎查看更多与《CodeIgniter中使用Smarty3基本配置》相关教程,学精学透。编程之家 52php.cn为您提供精彩教程。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |