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

夙愿已清 提交于 2019-12-11 15:51:02

问题


I am using Code Igniter, The HMVC library, and Smarty with this library.

Smarty is working fine by default, however if I try to use smarty's inheritance feature ( {extends file="master.tpl"}) then we run into an issue.

The extends feature does not look in the module views folder for the extended file (in the above's case master.tpl), instead it only looks in the application/views/ folder and throws an error if it cannot find it.

I could add APPPATH."modules/smartytest/views" to the $config['template_directory'] array in the smarty config file. but that throws an error for each item in the array it checks first for the file. filemtime(): stat failed for application/views/master.tpl

and that has the added issue of, if I have three modules all the the array and the modules all have a master.tpl then no matter what module I call the extend from it will load the first one found.

So, is there a way to get smarty's extend function to behave nicely with the HMVC modules?


回答1:


Ah, found a working solution,

in My_Parser.php edit the block at line 30 so it reads:

// 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');
}

The one drawback of this method is that smarty will look in your application/views folder before the module views folder. if someone knows a solution to that then it would be fantastic.




回答2:


The problem is that CI is not checking error_reporting() returns 0, because Smarty is using the @ control operator: So add the line at the top of the function "_exception_handler":

if (error_reporting() == 0) return;

To the "Common.php" file in the "_exception_handler" function (line 469), or create your own function with the same name before calling "CodeIgniter.php" in the index.php file.

Best!



来源:https://stackoverflow.com/questions/11111396/using-smarty-3-code-igniter-2-and-hmvc-together-with-smartys-inheritance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!