CodeIgniter整合Smarty的方法详解
框架(架构)  /  管理员 发布于 7年前   190
本文实例讲述了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项目中的application\libraries下面,其他的文件删除。 3、 在application\libraries目录下创建Ci_smarty.php文件,代码如下: 4、在application\config目录下创建配置文件smarty.php,代码如下: 5、在application\core创建MY_controller.php,代码如下: 至此,配置整合工作over了,下面我们要验证是否配置成功。 7、修改application\controllers的Welcome.php,代码如下: 然后,在application\views下创建test.html文件,代码如下: 在浏览器地址栏中输入:http://localhost/index.php/Welcome 结果显示: 大功告成! 更多关于CodeIgniter相关内容感兴趣的读者可查看本站专题:《codeigniter入门教程》、《CI(CodeIgniter)框架进阶教程》、《php优秀开发框架总结》、《ThinkPHP入门教程》、《ThinkPHP常用方法总结》、《Zend FrameWork框架入门教程》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》 希望本文所述对大家基于CodeIgniter框架的PHP程序设计有所帮助。if ( ! defined('BASEPATH')) exit('No direct script access allowed');require(APPPATH.'libraries/smarty-3.1.27/libs/Smarty.class.php');class Ci_smarty extends Smarty { protected $ci; public function __construct() { parent::__construct(); $this->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'); }}
if ( ! defined('BASEPATH')) exit('No direct script access allowed');$config['cache_lifetime'] = 60;$config['caching'] = false;$config['template_dir'] = APPPATH .'views';$config['compile_dir'] = APPPATH .'views/template_c';$config['cache_dir'] = APPPATH . 'views/cache';$config['config_dir'] = APPPATH . 'views/config';$config['use_sub_dirs'] = false; //子目录变量(是否在缓存文件夹中生成子目录)$config['left_delimiter'] = '{';$config['right_delimiter'] = '}';
class MY_controller extends CI_Controller { public function __construct() { parent::__construct(); } public function assign($key,$val) { $this->ci_smarty->assign($key,$val); } public function display($html) { $this->ci_smarty->display($html); }}
defined('BASEPATH') OR exit('No direct script access allowed');class Welcome extends MY_controller { public function index() { $test='ci 3.0.3 + smarty 3.1.27 配置成功'; $this->assign('test',$test); $this->display('test.html'); }}
{$test}
ci 3.0.3 + smarty 3.1.27 配置成功
您可能感兴趣的文章:
122 在
学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..123 在
Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..原梓番博客 在
在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..博主 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..1111 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号