我想创建基于 com_weblinks 的组件。
此组件将在单个页面上显示类别和链接。
在 3.0 中,我不明白如何在一个 View 中使用 2 个模型(类别模型和链接模型)。
最佳答案
第一种方法
我通过如下修改 Controller 来做到这一点(这是用户的 Controller )
function doThis(){ // the action in the controller "user"
// We will add a second model "bills"
$model = $this->getModel ( 'user' ); // get first model
$view = $this->getView ( 'user', 'html' ); // get view we want to use
$view->setModel( $model, true ); // true is for the default model
$billsModel = &$this->getModel ( 'bills' ); // get second model
$view->setModel( $billsModel );
$view->display(); // now our view has both models at hand
}
在 View 中,您可以简单地对模型进行操作
function display($tpl = null){
$userModel = &$this->getModel(); // get default model
$billsModel = &$this->getModel('bills'); // get second model
// do something nice with the models
parent::display($tpl); // now display the layout
}
替代方法
在 View 中直接加载模型:
function display($tpl = null){
// assuming the model's class is MycomponentModelBills
// second paramater is the model prefix
$actionsModel = JModel::getInstance('bills', 'MycomponentModel');
}
关于joomla - 如何在一个 View 中使用两个模型 - Joomla 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14559985/