php smarty ci,ci 框架整合smarty

第一步:安装CodeIgniter

解压后,复制文件夹下面的application、system、index.php至项目根目录中

5c4d43f22772b043e731df370970d476.png

第二步:安装Smarty

解压之后再将下载之后的smarty模板中2198249eb2afb5815639c0c4e089e408.png放到system文件目录

第三步:创建smarty.php

内容如下:

/**

* Smarty Class

*

* @package        CodeIgniter

* @subpackage    Libraries

* @category    Smarty

* @author        Kepler Gelotte

* @link        http://www.coolphptools.com/codeigniter-smarty

*/

/*

echo APPPATH."\n";

echo BASEPATH.'libs/Smarty.class.php';die;*/

require_once( BASEPATH.'libs/Smarty.class.php' );

class CI_Smarty extends Smarty {

function CI_Smarty()

{

parent::Smarty();

$this->compile_dir = APPPATH . "views/templates_c";

$this->template_dir = APPPATH . "views/templates";

$this->assign( 'APPPATH', APPPATH );

$this->assign( 'BASEPATH', BASEPATH );

log_message('debug', "Smarty Class Initialized");

}

function __construct()

{

parent::__construct();

$this->compile_dir = APPPATH . "views/templates_c";

$this->template_dir = APPPATH . "views/templates";

$this->assign( 'APPPATH', APPPATH );

$this->assign( 'BASEPATH', BASEPATH );

// Assign CodeIgniter object by reference to CI

if ( method_exists( $this, 'assignByRef') )

{

$ci =& get_instance();

$this->assignByRef("ci", $ci);

}

log_message('debug', "Smarty Class Initialized");

}

/**

*  Parse a template using the Smarty engine

*

* This is a convenience method that combines assign() and

* display() into one step.

*

* Values to assign are passed in an associative array of

* name => value pairs.

*

* If the output is to be returned as a string to the caller

* instead of being output, pass true as the third parameter.

*

* @access    public

* @param    string

* @param    array

* @param    bool

* @return    string

*/

function view($template, $data = array(), $return = FALSE)

{

foreach ($data as $key => $val)

{

$this->assign($key, $val);

}

if ($return == FALSE)

{

$CI =& get_instance();

if (method_exists( $CI->output, 'set_output' ))

{

$CI->output->set_output( $this->fetch($template) );

}

else

{

$CI->output->final_output = $this->fetch($template);

}

return;

}

else

{

return $this->fetch($template);

}

}

}

// END Smarty Class

?>

第四步:在application下config目录下的 autoload.php文件修改如下:

$autoload['libraries'] = array('smarty');

第五步:在application/views 下面创建templates_c 和 templates 二个文件夹

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值