CodeIgniter整合Smarty的要领详解
本篇章节讲授CodeIgniter整合Smarty的要领。分享给各人供各人参考,详细如下: CI3.0.2宣布后感受模板类照旧不怎么好用,并且不能编译。Smarty成果强盛,用风俗了Smarty标签,一样平常难以放弃,并且,是可以编译文件执行,速率快,我们可以把它们整合行使,补充CI的模板成果的不敷。我们整合行使的是CI版本3.0.3及 Smarty版本3.1.27。下面描写整合进程。 1、下载smarty-3.1.27 2 、解压smarty-3.1.27到CI项目中的applicationlibraries下面,其他的文件删除。 3、 在applicationlibraries目次下建设Ci_smarty.php文件,代码如下: ci = & get_instance();
$this->ci->load->config('smarty');//加载smarty的设置文件
$this->cache_lifetime =$this->ci->config->item('cache_lifetime');
$this->caching = $this->ci->config->item('caching');
$this->config_dir = $this->ci->config->item('config_dir');
$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');
}
}
4、在applicationconfig目次下建设设置文件smarty.php,代码如下: 5、在applicationcore建设MY_controller.php,代码如下: ci_smarty->assign($key,$val); } public function display($html) { $this->ci_smarty->display($html); } }至此,设置整合事变over了,下面我们要验证是否设置乐成。 7、修改applicationcontrollers的Welcome.php,代码如下: assign('test',$test);
$this->display('test.html');
}
}
然后,在applicationviews下建设test.html文件,代码如下: 在赏识器地点栏中输入: 功效表现: 大功告成! 更多关于CodeIgniter相干内容感乐趣的读者可查察本站专题:《》、《》、《》、《》、《》、《》、《》、《》及《》 但愿本文所述对各人基于CodeIgniter框架的PHP措施计划有所辅佐。 (编辑:湖南网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |