免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2932 | 回复: 0
打印 上一主题 下一主题

codeigniter配置smarty模板 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-07-18 12:42 |只看该作者 |倒序浏览
赚:高学平  

codeigniter配置smarty模板



codeigniter是一个比较不错的轻量级的php开发web frame,我将ci结合smarty模板解释器使用,现在ci配置smarty的方法给出:

①下载smarty的源码包并且解压

②将smarty源码包中的libs核心类库重命名为Smarty并且经文件夹copy到ci的项目目录下的libraries下,同时在libraries文件夹下建立Cismarty.php文件。

③在Cismarty.php文件中写入如下的code
  1. <?php<BR> if(!defined('BASEPATH'))exit('no dir');<BR> require_once (APPPATH.'libraries/Smarty/Smarty.class.php');<BR> class Cismarty extends Smarty<BR> {<BR>  protected $ci;<BR>  function __construct()<BR>  {<BR>   parent::__construct();<BR>   $this->ci = &get_instance();<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('caching_dir');<BR>   $this->config_dir = $this->ci->config->item('config_dir');<BR>   $this->template_ext = $this->ci->config->item('template_ext');<BR>   $this->caching = $this->ci->config->item('caching');<BR>   $this->cache_lifetime = $this->ci->config->item('cache_lifetime');<BR>  }<BR> }
复制代码
④在项目目录下的cofig文件夹建立smarty.php文件,并且写入如下代码:
  1. <?php<BR> if (! defined('BASEPATH')) exit('no direct base');<BR> $config['template_dir'] = APPPATH.'views';<BR> $config['compile_dir'] = FCPATH.'template_c';<BR> $config['caching_dir'] = FCPATH.'cache';<BR> $config['config_dir'] = FCPATH.'config';<BR> $config['caching'] = false;<BR> $config['cache_lifetime'] = '60';<BR> $config['template_ext'] = '.html';
复制代码
⑤在项目目录下的config文件夹中的autoload.php文件中写入以下代码:
  1. $autoload['config'] = array('smarty');
  2. $autoload['libraries'] = array('cismarty');
  3. 至此配置完毕,以下给出简单的测试程序

  4. view sourceprint?    class Start extends CI_Controller  

  5.     {  

  6.         function __construct()  

  7.         {  

  8.             parent::__construct();  

  9.             $this->load->database();  

  10. //          $this->load->library('cismarty');  

  11.    

  12.         }  

  13.    

  14.         function smarty()  

  15.         {  

  16.             $title = 'title';  

  17.             $this->cismarty->assign('title',$title);  

  18.             $this->cismarty->display("test.html");  

  19.         }  

  20.     }
复制代码
现在自己在application下的views下建立一个test.html文件,传一个数据过去,如果配置正确那么可以看到测试页面和数据。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP