ci2 整合smarty3.0

(1)下载smarty ,这儿下载的是 smarty-3.1.29

(2)解压到 application/librarys/文件夹下面,形成 application/librarys/smarty-3.1.29/

(3)在application/librarys/Cismarty.php新建 Cismarty.php文件

Cismarty.php 文件修改

<?php

if(!defined('BASEPATH')) EXIT('No direct script asscess allowed');
require_once( APPPATH . 'libraries/smarty-3.1.29/libs/Smarty.class.php' );

class Cismarty extends Smarty
{
	protected $ci;
	public function __construct()
	{
		parent::__construct();
		$this->ci =& get_instance();
		$this->ci->load->config('smarty');// 加载smarty 的配置文件
		// 获取相关的配置项
		$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->config_dir     = $this->ci->config->item('config_dir');
		$this->caching        = $this->ci->config->item('caching');
		$this->cache_lifetime = $this->ci->config->item('lefetime');
		$this->right_delimiter= $this->ci->config->item('right_delimiter');
		$this->left_delimiter = $this->ci->config->item('left_delimiter');
	}
}

(4)配置smarty配置项

<?php
if( !defined('BASEPATH')) exit('No direct script access allowed');
	
$config['theme']    = 'default';
$config['template_dir']    = FCPATH . 'www/temp';
$config['compile_dir']    = FCPATH . 'www/temp_c';
$config['cache_dir']    = FCPATH . 'www/cache';
$config['config_dir']    = FCPATH . 'www/configs';
$config['caching']    = false;
$config['lefttime']    = 0;
$config['left_delimiter'] = '<{';
$config['right_delimiter'] = '}>';

(5) 在index.php同级目录下,建立文件夹

www

www/temp

www/temp_c

www/cache/

www/configs

(6)开启自由加载,application/config/autoload.php

中修改代码  $autoload['libraries'] = array('Cismarty');

(7)验证

新建

application/core/MY_Controller.php

<?php 
if (!defined('BASEPATH')) exit('No direct access allowed');

class MY_Controller extends CI_Controller
{
	public function __construct()
	{
		parent::__construct();
	}

	public function assign($key, $val)
	{
		$this->cismarty->assign($key, $val);
	}

	public function display($html)
	{
		
		$this->cismarty->display($html);
	}
}

修改application/controller.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Welcome extends MY_Controller 
{


	public function index()
	{
		$say = 'hello world';
		$this->assign('say', $say);
		$this->display("index.html");
	}
}

新建文件www/temp/index.html

<!DOCTYPE>
<html>
<head>
<title></title>
</head>
<body>
<{$say}>
</body>
</html>

最后 >sudo chmod -R 777 www

访问localhost/index.php

输出 hello world

配置完成。

转载于:https://my.oschina.net/u/2280651/blog/552542

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值