Codeigniter轻松整合smarty
2013-12-20 00:00
447 查看
smarty的模板机制很强大,一般情况下CI无需整合其他模板标签,因为PHP本身就是一种标签,简单易用。codeigniter整合smarty教程(我用的都是最新版本)如下:
第一步:下载codeigniter最新版本:http://codeigniter.org.cn/downloads
第二步:下载smarty最新版本:http://www.smarty.net/download
第三步:
配置步骤:
(1)将smarty拷贝到application/libraries下,然后再根目录下下新建templates,templates_c,config,cache目录,结构如下:
(2)入口文件新增:define('ROOT', dirname(__FILE__));
(3)libraries下新建CI_Smarty.php
controller中使用:
新建test.tpl模板:
测试成功!
第一步:下载codeigniter最新版本:http://codeigniter.org.cn/downloads
第二步:下载smarty最新版本:http://www.smarty.net/download
第三步:
配置步骤:
(1)将smarty拷贝到application/libraries下,然后再根目录下下新建templates,templates_c,config,cache目录,结构如下:
(2)入口文件新增:define('ROOT', dirname(__FILE__));
(3)libraries下新建CI_Smarty.php
<?php defined('BASEPATH') or die('Access restricted!'); require(APPPATH . 'libraries/smarty/Smarty.class.php'); class CI_Smarty extends Smarty { public function __construct($template_dir = '', $compile_dir = '', $config_dir = '', $cache_dir = '') { parent::__construct(); if (is_array($template_dir)) { foreach ($template_dir as $key => $value) { $this->$key = $value; } } else { //ROOT是Codeigniter在入口文件index.php定义的本web应用的根目录 $this->template_dir = $template_dir ? $template_dir : ROOT . '/templates'; $this->compile_dir = $compile_dir ? $compile_dir : ROOT . '/templates_c'; $this->config_dir = $config_dir ? $config_dir : ROOT . '/config'; $this->cache_dir = $cache_dir ? $cache_dir : ROOT . '/cache'; } } }
controller中使用:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); // by www.phpddt.com class Welcome extends CI_Controller { public function __construct() { parent::__construct(); $this->load->library('CI_Smarty'); } public function test() { $this->ci_smarty->assign('test', 'smarty'); $this->ci_smarty->display('test.tpl'); } } /* End of file welcome.php */ /* Location: ./application/controllers/welcome.php */
新建test.tpl模板:
<html> <body> 这是 {$test} 测试 </body> </html>
测试成功!
相关文章推荐
- [初级] Codeigniter3.X 整合 Smarty3.X
- CI轻松整合smarty
- CodeIgniter整合smarty
- Codeigniter框架整合Smarty引擎DEMO
- CodeIgniter2.1.3整合smarty3.1.12
- [初级] Codeigniter3.X 整合 Smarty3.X
- codeigniter整合smarty
- Codeigniter整合smarty
- CodeIgniter整合Smarty的方法详解
- Codeigniter整合Ucenter同步登陆
- PhpMVC框架整合smarty模板
- 教程: CodeIgniter 整合 UCenter 全攻略
- CodeIgniter + smarty 实现widget功能
- ZF0.15成功整合Smarty2.6.14!傻瓜化教程
- 用JDom轻松整合Java和XML
- Zendframework 1.6整合Smarty
- Codeigniter整合PJAX(pushstate+ajax)实现无刷新页面
- 整合了一个PHP分页函数与smarty与程序显示的例子
- yii整合smarty【转】
- ci整合Smarty-3.1.18