【问题标题】:Using Smarty 3, Code Igniter 2, and HMVC together with smarty's inheritance?使用 Smarty 3、Code Igniter 2 和 HMVC 以及 smarty 的继承?
【发布时间】:2012-06-22 02:35:27
【问题描述】:

我正在使用 Code Igniter、HMVC library 和 Smarty 和 this library

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

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

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

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

那么,有没有办法让 smarty 的扩展函数与 HMVC 模块很好地配合?

【问题讨论】:

    标签: php codeigniter extend hmvc smarty3


    【解决方案1】:

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

    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 会在模块视图文件夹之前查看您的应用程序/视图文件夹。如果有人知道解决方案,那就太好了。

    【讨论】:

    • protected function _find_view($file) { // 是的,忠实的视图文件夹 $view_folder = APPPATH . '意见/'; // 我们的 HMVC 模块的位置 $modules_folder = APPPATH . '模块/'; // 最终路径 $final_path = FALSE; //添加下面一行!!!!!!!!!!!!!!! $this->_module = $this->CI->router->fetch_module(); // 确保我们有一个模块 if ($this->_module !== '') {
    • 我有类似的问题,但如果你能解决它,我的 CI smarty 不使用 HMVC,赏金是你的。还有一些时间。 stackoverflow.com/questions/25541382/…
    【解决方案2】:

    问题在于 CI 没有检查 error_reporting() 返回 0,因为 Smarty 使用了 @ 控制运算符: 所以在函数“_exception_handler”的顶部添加一行:

    if (error_reporting() == 0) return;

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

    最好的!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-27
      • 2011-08-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-11
      相关资源
      最近更新 更多