0

我在 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);

    }

但是,视图不能显示到窗体!!!

帮我!!谢谢你们。

4

1 回答 1

0

代替: $this->form2 = $this->get('Form', 'version'); 您应该使用: $this->form2 = $this->getForm();

对我来说它有效。我想只有一个默认模型,这就是为什么我们应该以其他方式调用模型的函数。

于 2013-11-25T17:04:49.013 回答