008shanke 发表于 2011-3-30 10:39:41

CodeIgniter2.0.1和smarty3.0.7无缝整合,新手必修技打包下载

CodeIgniter2.0.1和smarty3.0.7无缝整合都是全新版本 和 以往的插件方法不同是很好的无缝整合

解释:application\libraries\Smarty.php



<?phpif (!defined('BASEPATH')) exit('No direct script access allowed');

require_once( BASEPATH.'libs/smarty/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");
}

   function view($template, $data = array(), $return = FALSE)
{
foreach ($data as $key => $val)
{
   $this->assign($key, $val);
}

if ($return == FALSE)
{

//注意这里使用了get_instance();但是在output类中final_output是受保护的,所以需要修改修饰符!

   $CI =& get_instance();

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

   return;
}
else
{
   return $this->fetch($template);
}
}
}


huoshanzuoer 发表于 2011-3-30 15:20:11

占位,好好看看

iyuki0430 发表于 2011-3-31 09:01:19

看样子不错, 不过不是很喜欢这种破坏结构的

Capricornus 发表于 2011-3-31 09:09:44

好吧,标记一下,做项目刚好需要用到!

as3291363 发表于 2011-3-31 14:33:26

收藏...留著以後使用.

mulanqishi 发表于 2011-3-31 20:53:35

mark ,很久没解决的问题,因为看得都是旧版本的指南。以后再用……多谢

hainuo 发表于 2011-4-1 08:39:48

感觉为了高效,还是放弃模板引擎好一点。

kissboa 发表于 2011-4-3 07:54:12

不是有内置模板么?

goyoyo315 发表于 2011-4-4 22:06:37

还用smarty啊,我已经抛弃了smarty这种东西,太浪费资源了。

smartweb 发表于 2011-4-7 22:24:03

明显是用新手来骗人,新手哪有这样入门的呢?
页: [1] 2
查看完整版本: CodeIgniter2.0.1和smarty3.0.7无缝整合,新手必修技打包下载