2014-05-22 56 views
-1

我正在開發一個帶有joomla 3的組件,而我對MVC框架並不十分熟悉。Joomla - 一個視圖的組件 - 多個模型的MVC

該組件將管理我網站上的用戶註冊。 有3種不同類型的用戶。 必須顯示每種類型的自定義視圖 - >每個用戶的一個佈局(Usertype1,Usertype2,Usertype3)。

關於註冊有些方法對所有userType都是類似的,但有些方法是特定的(比如getForm()函數)。

因此,我認爲,最好的選擇是爲每個用戶類型一個模型,然後適應就在URL佈局加載到控制器的型號:

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; 
    } 

此代碼不起作用。你認爲我做出了正確的選擇嗎?

回答

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方法

相關問題