codeigniter + hmvc + smarty or using common libraries within modules

荒凉一梦 提交于 2019-12-25 07:47:51

问题


I'm building a website using CI, HMVC and Smarty. It's my first time using HMVC and I don't understand how I can use common libraries within the modules.

I prefer using Smarty on my sites and usually it's a piece of cake: I create a wrapper for smarty, autoload it and use it in controllers where necessary. But now I need to use smarty within the module controller and I don't know how to access it. Any ideas how I can do that?

I've been researching the issue for a couple of days, with no luck.

There are some answers which I just don't get: like this one

EDIT: CI 2.1.0, HMVC 5.4, Smarty 3.1.6 (but this is irrelevant)


回答1:


Here are a couple of ways:

In application/libraries

Just put the common libraries in application/libraries folder and load using $this->load->library('my_library');

Create a common module

Another option would be to create a new module, lets say common, in which you can have folders libraries,models,helpers. Here you can put files which are common to other modules. You can then load them using $this->load->library('common/my_library');

I hope that helps.




回答2:


You can extend your smarty in your modules with modules. path.

Example:

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";
    }
}

And load this class in your modules class constructor like this:

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

Note: don't load smarty in config/autoload.php it may create conflict in loading.



来源:https://stackoverflow.com/questions/8376032/codeigniter-hmvc-smarty-or-using-common-libraries-within-modules

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