0

私は CI に少し精通しており、現在それを使用して Web ポータルを構築しようとしています。ウィジェット/モジュールを受け入れるのに十分な柔軟性を持たせようとしています。コンポーネントが joomla にどのようにあるかと同じように。

このためには、(私は思う) モジュールを作成する必要がありますが、残念な部分の CI はデフォルトでモジュールを受け入れません。しかし、HMVC または Modular 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

    }
}

上記のコードは、私が取得しようとしているものです。これらを行うためのより良い方法があるかもしれません。いずれにせよ、お返事お待ちしております……。

4

1 に答える 1

1

ユーザーコントローラー

//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
}
于 2011-12-27T09:15:59.157 に答える