vaphp整合smart模板问题
<br>目前正在做一个小项目,选择Ci框架也是第一次使用,发现CI没有内置的模版引擎,传统的php、html混写有点不习惯咯被惯坏了,决定将smarty模版引擎整合到CI框架中。 <br>步骤如下: <br>下载:ci,smarty <br>配署ci 在这里就不多说了…… <br>1. 将下载好的smarty包的lib文件上传到ci中的libraries 文件中,将取名称修改为smarty,在libraries文件新建cismarty.php文件,内容如下: <br>if (!defined('BASEPATH')) exit("no direct script access allowd"); <br>//以下是加载smarty的类文件 <br>require_once(APPPATH.'libraries/smarty/Smarty.class.php'); <br>//定义cismarty类,继承smarty类 <br>class cismarty extends Smarty{ <br> //定义一个受保护的变量, <br> protected $ci; <br> <br> function __construct(){ <br> parent::__construct(); <br> //引用实例化CI,这里主要是将smarty的配置文件写到ci中,以方便程序管理 <br> $this->ci = & get_instance(); <br> //加载ci的新建的smarty配置文件 <br> $this->ci->load->config('smarty'); <br> $this->cache_lifetime = $this->ci->config->item('cache_lifetime'); <br> $this->caching = $this->ci->config->item('caching'); <br> $this->template_dir = $this->ci->config->item('template_dir'); <br> $this->compile_dir = $this->ci->config->item('compile_dir'); <br> $this->cache_dir = $this->ci->config->item('cache_dir'); <br> $this->use_sub_dirs = $this->ci->config->item('use_sub_dirs'); <br> $this->left_delimiter = $this->ci->config->item('left_delimiter'); <br> $this->right_delimiter = $this->ci->config->item('right_delimiter'); <br> <br>2. 在config下新建smarty.php配置文件 <br><?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); <br>$config['cache_lifetime'] = 30*24*3600; //更新周期 <br>$config['caching'] = false;//是否使用缓存,项目在调试期间,不建议启用缓存 <br>$config['template_dir'] = APPPATH.'views'; //设置模板目录 <br>$config['compile_dir'] = APPPATH.'views/template_c'; //设置编译目录 <br>$config['cache_dir'] = APPPATH.'views/cache';//缓存文件夹 <br>$config['use_sub_dirs'] = true; //子目录变量(是否在缓存文件夹中生成子目录) <br>$config['left_delimiter'] = '<{'; <br>$config['right_delimiter'] = '}>'; <br> <br> <br>3. 在CI里重载smarty的 assign 和 display方法 <br>在框架根目录下core/目录下新建控制器继承CI基类,MY_Controller <br><?php if (!defined('BASEPATH')) exit('No direct access allowed.'); <br>class MY_Controller extends CI_Controller { <br> public function __construct() { <br> parent::__construct(); <br> } <br> <br> public function assign($key,$val) { <br> $this->cismarty->assign($key,$val); <br> } <br> <br> public function display($html) { <br> $this->cismarty->display($html); <br> } <br>} <br> <br>4. 修改Config文件下的autoload.php 自动加载类文件 <br>$autoload['libraries'] = array('cismarty'); <br>到此配置已完成. <br>第3步要在core文件夹下建my_controller,但是vsphp创建的ci框架里面没有这个文件夹,我自己建了个core文件夹在里面创建了my_controller。运行的时候报错找不到my_controller类。然后我在用到这个类的地方引用这个文件就好了。但是这样太麻烦了每个文件都要引用。有没有别的处理方法。
------解决方案--------------------
查找包含 __autoload 或 spl_autoload_register 字样的文件
修改相关代码
------解决方案--------------------
没定义一个类 你让他继承这个my_controller类就可以了啊
------解决方案--------------------
在index文件中 默认就加载这个文件
婚纱摄影网站源码,phpcms模板,婚纱摄影网站模板Ronger婚纱摄影phpcms整站源码是一个采用了PHPcmsV9作为后台的婚纱摄影网站源码,本站适合用作婚纱类的企业PC网站。安装步骤:整站打包请自行上传ty00.sql数据库文件,数据库文件修改目录为/caches/configs/后台账号和密码均为:phpcms无法在后台更新的问题,存在这种问题的只有俩种可能,请看下面内容:一:服务器文件










