vaphp整合smart模板问题
目前正在做一个小项目,选择ci框架也是第一次使用,发现ci没有内置的模版引擎,传统的php、html混写有点不习惯咯被惯坏了,决定将smarty模版引擎整合到ci框架中。
步骤如下:
下载:ci,smarty
配署ci 在这里就不多说了……
1. 将下载好的smarty包的lib文件上传到ci中的libraries 文件中,将取名称修改为smarty,在libraries文件新建cismarty.php文件,内容如下:
if (!defined('basepath')) exit(no direct script access allowd);
//以下是加载smarty的类文件
require_once(apppath.'libraries/smarty/smarty.class.php');
//定义cismarty类,继承smarty类
class cismarty extends smarty{
//定义一个受保护的变量,
protected $ci;
function __construct(){
parent::__construct();
//引用实例化ci,这里主要是将smarty的配置文件写到ci中,以方便程序管理
$this->ci = & get_instance();
//加载ci的新建的smarty配置文件
$this->ci->load->config('smarty');
$this->cache_lifetime = $this->ci->config->item('cache_lifetime');
$this->caching = $this->ci->config->item('caching');
$this->template_dir = $this->ci->config->item('template_dir');
$this->compile_dir = $this->ci->config->item('compile_dir');
$this->cache_dir = $this->ci->config->item('cache_dir');
$this->use_sub_dirs = $this->ci->config->item('use_sub_dirs');
$this->left_delimiter = $this->ci->config->item('left_delimiter');
$this->right_delimiter = $this->ci->config->item('right_delimiter');
2. 在config下新建smarty.php配置文件
assign($key,$val);
}
public function display($html) {
$this->cismarty->display($html);
}
}
4. 修改config文件下的autoload.php 自动加载类文件
$autoload['libraries'] = array('cismarty');
到此配置已完成.
第3步要在core文件夹下建my_controller,但是vsphp创建的ci框架里面没有这个文件夹,我自己建了个core文件夹在里面创建了my_controller。运行的时候报错找不到my_controller类。然后我在用到这个类的地方引用这个文件就好了。但是这样太麻烦了每个文件都要引用。有没有别的处理方法。
------解决方案--------------------
查找包含 __autoload 或 spl_autoload_register 字样的文件
修改相关代码
------解决方案--------------------
没定义一个类 你让他继承这个my_controller类就可以了啊
------解决方案--------------------
在index文件中 默认就加载这个文件