2013-04-15 52 views
0

我在joomla 2.5中編寫了一個組件。我想要一個視圖在視圖上使用多個模型。我看到Multiple models for a view without controllers視圖上的多個模型Joomla 2.5

我的代碼: 在類控制器(Controller.php這樣)

public function display($cachable = false, $urlparams = false) 
{ 
     AppHelper::addSubmenu(JRequest::getCmd('view', 'apps')); 
     JRequest::setVar('view', JRequest::getCmd('view', 'apps')); 

     $model = $this->getModel('app'); // get first model 
     $view = $this->getView('apps', 'html'); // get view we want to use 
     $view->setModel($model, true); // true is for the default model 

     $vermodel = &$this->getModel('version'); // get second model 
     $this->assignRef('version', $vermodel); 

     $view->setModel($vermodel); 
     var_dump($this); 

     parent::display($cachable); 
     return $this; 
} 

在類視圖(view.html.php)

public function display($tpl = null) 
{ 
     // Initialiase variables. 
     $this->form = $this->get('Form'); 

     $this->item = $this->get('Item'); 
     $this->state = $this->get('State'); 
     $this->form2 = $this->get('Form', 'version'); 
     // var_dump($this->form2); 

    } 

但是,圖不能顯示以形成! !

幫幫我!謝謝你們。的

+0

您是否檢查過 - 視圖中是否提供了'版本'模型? –

回答

0

Insteed: $this->form2 = $this->get('Form', 'version'); 你應該使用: $this->form2 = $this->getForm();

對我來說,它的工作原理。我想只有一個默認模型,這就是爲什麼我們應該以其他方式調用模型的功能。