2011-12-27 5 views
0

저는 CI에 조금 익숙해졌습니다. 이제는 그것을 사용하여 웹 포털을 구축하려고합니다. 위젯/모듈을 수용 할만큼 유연하게 만들려고합니다. 구성 요소가 joomla하는 방법처럼.Codeignitor의 모듈 구현을위한 최상의 기술

이 경우 모듈을 만들어야하지만 기본적으로 슬픈 파트 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 

    } 
} 

내가 얻기 위해 노력하고 있습니다 만 무엇인가 ... 이런 식으로 어느 정도를 기본 사이트로 컨트롤러와 내가 무엇을 찾고의 기능을한다 걸릴. 이를 수행하는 더 좋은 방법이있을 수 있습니다. 이 모듈의 수에 액세스 할 수 있습니다

귀하의 의견 안쪽에 한 번
//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 
} 
} 

나는 당신의 대답을 기대하고 어느 쪽이든 .....

답변

1

사용자 컨트롤러 ...

//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 
} 
+0

나는 매우 혼란 스럽다 ..... – joomlearner

+0

Ive는 코드를 더 잘 포맷하기 위해 나의 대답을 업데이트했다 – Philip

+0

그래서 제안하고있다. 나는 모듈을 위해 HMVC를 사용해야한다 ... – joomlearner

관련 문제