2014-05-22 58 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方法

相关问题