使用Smarty 3,代码Igniter 2和HMVC连同smarty的继承? [英] Using Smarty 3, Code Igniter 2, and HMVC together with smarty's inheritance?

查看:160
本文介绍了使用Smarty 3,代码Igniter 2和HMVC连同smarty的继承?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用代码Igniter, HMVC库和Smarty与< a href =http://ilikekillnerds.com/2010/11/using-smarty-3-in-codeigniter-2-a-really-tiny-ci-library/ =nofollow>此库

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

Smarty默认工作正常,但是如果我尝试使用smarty的继承功能( {extends file =master.tpl}

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.

扩展功能不会在扩展文件的模块视图文件夹中查找(在上述情况下) master.tpl ),而是只在 application / views / 文件夹中查找,并且如果找不到

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.

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

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

如果我有三个模块所有的数组和模块都有一个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.

因此,有没有办法让smarty的扩展函数与HMVC模块表现得很好?

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

推荐答案

解决方案,

My_Parser.php 中编辑第30行的块,如下所示:

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

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

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.

这篇关于使用Smarty 3,代码Igniter 2和HMVC连同smarty的继承?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆