2014-05-22 2 views
-1

joomla 3을 사용하여 구성 요소를 개발 중이며 MVC 프레임 워크에 익숙하지 않습니다.Joomla - 구성 요소 용 MVC - 하나의보기 용 다중 모델

구성 요소는 내 웹 사이트에서 사용자 등록을 관리합니다. 3 가지 유형의 사용자가 있습니다. 사용자별로 하나의 레이아웃 (Usertype1, Usertype2, Usertype3)이 각 유형에 대해 사용자 정의보기를 표시해야합니다.

등록과 관련하여 일부 메소드는 모든 userType에 대해 동일하지만 일부는 구체적입니다 (예 : getForm()). 이 코드는 작동하지 않습니다

public function display($cachable = false, $urlparams = false){ 

     $view = $this->getView('registration'); 
     $layout = $this->input->get('layout'); 
     switch ($layout) { 
       case "userType1": 
        $view->setModel($this->getModel('userType1'), true); 
        $view->display(); 
        break; 
       case "userType2": 
        $view->setModel($this->getModel('userType2'), true); 
        $view->display(); 
        break; 
       case "userType3": 
        $view->setModel($this->getModel('userType3'), true); 
        $view->display(); 
        break; 
      } 
     parent::display(); 
     return $this; 
    } 

:

그래서 나는 최선의 선택은 각 사용자 유형에 대한 하나 개의 모델을 만드는 것이 었습니다 다음 URL에서 레이아웃에 관한 컨트롤러에로드 된 모델을 적용 할 수 있다고 생각했다. .. 내가 올바른 선택을했다고 생각합니까?

답변

0

그냥 내용은 다음 코드는 완벽하게 작동 다음 view.html.php에서

public function display($tpl = null) 
    { 
    $document = JFactory::getDocument(); 
    $app = JFactory::getApplication(); 

    $layout = $app->input->get('layout'); 
    switch ($layout) { 
      case "UserType1": 
       $model = JModelLegacy::getInstance('userType1', 'ComponentModel'); 
       break; 
      case "userType2": 
       $model = JModelLegacy::getInstance('userType2', 'ComponentModel'); 
       break; 
      case "userType3": 
       $model = JModelLegacy::getInstance('userType3', 'ComponentModel'); 
       break; 
    } 
    $this->form = $model->getForm(); 

    //langage 
    $lang = JFactory::getLanguage(); 
    $this->tag = $lang->getTag(); 

    parent::display($tpl); 
    } 

내 유일한 관심사는 : 나는 확실하지 않다, 그래서 내가 컨트롤러를 사용하지 않는 가장 깨끗한 작업 방법 MVC 접근 방식