Codeigniter 中模块实现的最佳技术
我对 CI 有点熟悉,现在我正在尝试使用它构建一个门户网站。我试图使其足够灵活以接受小部件/模块。就像 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
}
}
上面的代码正是我想要得到的。可能有更好的方法来做到这些。不管怎样,我期待着您的回复......
I am a little familiar with CI, and now I am trying to build a web portal using it. I am trying to make it flexible enough to accept widgets/modules. Just like how components are to joomla.
For this, (I think) I should create modules, but the sad part CI by default does not accept any modules. But through HMVC or Modular CI, even this might be possible, but as i haven't used them before, I do not know which would fit in my case, for the long run.
Basically, I would like to communicate with other modules and their controller through a common controller. Kind of like a front controller.
For example take my default controller as Site and the functionality of what I am looking is somewhat like this...
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
}
}
Above code is just what I am trying to get. There might be better way to do these. Either way I am looking forward to your replies.....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
用户控制器
进入视图后,您可以访问任意数量的模块...
User Controller
once inside your views you can access any number of modules...