前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >codeigniter3整合smarty

codeigniter3整合smarty

作者头像
py3study
发布2020-01-07 10:07:38
8440
发布2020-01-07 10:07:38
举报
文章被收录于专栏:python3python3
  1. 切换到ci路径下
  2. 在application/libraries创建smarty文件夹,并将解压好的Smarty库中的libs文件夹复制到Smarty文件夹中
  3. 在application/config下创建smarty.php, 代码如下: <?php if (!defined('BASEPATH')) { exit('No direct script access allowed'); } $config['cache_lifetime'] = 60; $config['caching'] = false; $config['template_dir'] = APPPATH . 'views/templates'; $config['compile_dir'] = APPPATH . 'views/templates_c'; $config['cache_dir'] = APPPATH . 'views/cache'; $config['config_dir'] = APPPATH . 'views/config'; $config['use_sub_dirs'] = false; //子目录变量(是否在缓存文件夹中生成子目录) $config['left_delimiter'] = '{'; $config['right_delimiter'] = '}';
  4. 在application/libraries下创建一个Ci_Smarty.php,代码如下 <?php if (!defined('BASEPATH')) { exit('No direct script access allowed'); } require_once APPPATH.'libraries/smarty/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'); } }
  5. 打开application/config/autoload.php 修改 $autoload['libraries'] = array(''); 改为 $autoload['libraries'] = array('Ci_Smarty');
  6. application/core下新建一个MY_Controller.php ,代码如下: <?php 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); } }
  7. 在views下创建templates目录
  8. 在templates下新建一个测试模板test.tpl hello.world
  9. 在controllers下新建一个测试文件Pages.php继承MY_controller <?php class Pages extends MY_controller {     public function index()     {         $this->display('test.tpl');     } }
wKiom1lbQu6iEPTvAAAoA7665nE783.jpg-wh_50
wKiom1lbQu6iEPTvAAAoA7665nE783.jpg-wh_50
  1. 至此完成
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-09-17 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档