Codeigniter + HMVC + smarty或在模块中使用通用库


codeigniter + hmvc + smarty or using common libraries within modules

我正在使用CI, HMVC和Smarty建立一个网站。这是我第一次使用HMVC,我不明白如何在模块中使用通用库。

我更喜欢在我的网站上使用Smarty,通常它是小菜一碟:我为Smarty创建一个包装器,自动加载它,并在必要时在控制器中使用它。但现在我需要在模块控制器内使用智能,我不知道如何访问它。知道怎么做吗?

我已经研究这个问题好几天了,没有运气。

有一些答案我就是不明白:比如这个

编辑:CI 2.1.0, HMVC 5.4, Smarty 3.1.6(但这是无关的)

这里有几个方法:

应用程序/图书馆

将常用库放在application/libraries文件夹中,然后使用$this->load->library('my_library');加载

创建公共模块

另一个选项是创建一个新模块,比如common,其中可以有文件夹libraries, models, helpers。在这里,您可以放置其他模块常用的文件。然后你可以使用$this->load->library('common/my_library');

加载它们

你可以在你的模块中使用模块扩展你的智能。路径。

的例子:

class MySmartie extends Smartie {
    function __construct()
    {
        parent::__construct();
        $this->template_dir = APPPATH . "modules/client/views/templates";
        $this->compile_dir = APPPATH . "modules/client/views/templates_c";
    }
}

然后在你的模块类构造函数中加载这个类,像这样:

public function __construct()
{
   $this->load->library(['mysmartie' => 'smarty']);
}

注意:不要在config/autolload .php中加载smarty,它可能会在加载时产生冲突。