Codeigniter中模块实现的最佳技术

时间:2011-12-27 05:45:08

标签: codeigniter module codeigniter-2 hmvc

我对CI有点熟悉,现在我正在尝试使用它构建一个Web门户。我试图使其足够灵活,以接受小部件/模块。就像joomla的组件一样。

为此,(我认为)我应该创建模块,但默认的悲伤部分CI不接受任何模块。但是通过HMVC或模块化CI,即使这可能也是可能的,但是因为我之前没有使用它们,所以从长远来看,我不知道哪种情况适合我的情况。

基本上,我想通过一个通用控制器与其他模块及其控制器进行通信。有点像前控制器。

例如,将我的默认控制器作为站点,我正在寻找的功能有点像这样......

class Site extends CI_Controller {
    public function index() {
        $appName = $this -> uri -> segment(1); // Take this as app name
        $appControllerName = $this -> uri -> segment(2); // Take this as app controller name


        $this -> load -> module($appName); //Loading our app Module

        $this -> $appName -> load -> controller($appControllerName);

        $this -> $appName -> $appControllerName -> render(); 
        // Take Render() as one of the common method that all the modules controller should have and is reponsible for rendering the HTML

    }
}

以上代码正是我想要的。可能有更好的方法来做到这些。无论哪种方式,我期待你的回复.....

0 个答案:

没有答案