[英]Best technique for module implementation in Codeigniter
我对CI有点熟悉,现在我正尝试使用它来构建Web门户。 我正在尝试使其足够灵活以接受小部件/模块。 就像joomla的组件一样。
为此,(我认为)我应该创建模块,但是默认情况下,可悲的部分CI不接受任何模块。 但是通过HMVC或Modular CI,甚至有可能做到这一点,但是由于我以前从未使用过它们,从长远来看,我不知道哪种方法适合我的情况。
基本上,我想通过一个公共控制器与其他模块及其控制器进行通信。 有点像前端控制器。
例如,以我的默认控制器为Site,我正在寻找的功能有点像这样...
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
}
}
上面的代码正是我想要得到的。 可能会有更好的方法来执行这些操作。 无论哪种方式,我都期待您的回复.....
用户控制器
//MX_Controller is the HMVC controller, so anything extending
//this class is a Module
class User extends MX_Controller{
//Public function hidden from URL but accessed via Module
public function _comments($user_id){
//grab comments for this users from your database
//return as an array or object
}
}
一旦进入视图,您就可以访问任意数量的模块...
//Dashboard_view.php
//Module One
foreach( Modules::run('User/_comments', $user_id ) as $user_comments )
{
// return all comments for this user
}
//Module Two
foreach( Modules::run('Widgets/_show_random_stuff', $user_id ) as $user_widgets )
{
// return all widgets for this user
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.