使用 Smarty 3、Code Igniter 2 和 HMVC 以及 smarty 的继承


Using Smarty 3, Code Igniter 2, and HMVC together with smarty's inheritance?

我正在使用Code Igniter,HMVC库和Smarty。

默认情况下,Smarty工作正常,但是如果我尝试使用smarty的继承功能({extends file="master.tpl"}),那么我们就会遇到问题。

扩展

功能不会在模块视图文件夹中查找扩展文件(在上述情况下master.tpl),而是仅在application/views/文件夹中查找,如果找不到它,则会抛出错误。

我可以将APPPATH."modules/smartytest/views"添加到智能配置文件中的$config['template_directory']数组中。 但这会为它首先检查文件的数组中的每个项目抛出错误。 filemtime(): stat failed for application/views/master.tpl

这有一个额外的问题,如果我有三个模块,所有的数组和模块都有一个 master.tpl,那么无论我从哪个模块调用扩展都会加载找到的第一个。

那么,有没有办法让smarty的扩展功能在HMVC模块上表现良好?

啊,找到了一个可行的解决方案,

My_Parser.php编辑第 30 行的块,使其显示为:

// Modular Separation / Modular Extensions has been detected
if (method_exists( $this->CI->router, 'fetch_module' ))
{
    $this->_module  = $this->CI->router->fetch_module();
    //add the current module view folder as a template directory
    if ($this->_module !== '')
        $this->CI->smarty->addTemplateDir(APPPATH."modules/".$this->_module.'/views');
}

这种方法的一个缺点是 smarty 会在模块视图文件夹之前查看您的应用程序/视图文件夹。 如果有人知道解决方案,那就太棒了。

问题是 CI 没有检查 error_reporting() 返回 0,因为 Smarty 使用的是 @ 控制运算符:因此,在函数"_exception_handler"的顶部添加行:

if (error_reporting() == 0) return;

到"_exception_handler"函数(第 469 行)中的"Common.php"文件,或者在索引.php文件中调用"CodeIgniter.php"之前创建自己的同名函数。

最好!