joomla - 如何在一个 View 中使用两个模型 - Joomla 3

标签 joomla joomla2.5 joomla3.0

我想创建基于 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/

相关文章:

javascript - 将 html 布局转移到 joomla 模板 javascript 不起作用

joomla - Joomla 扩展中的简单许可证管理器?

php - Joomla:JDatabase 与 PHP 的直接 SQL 操作

css - 需要为 Joomla 3 模板修改 style.css

mysql - 我可以在我为 SugarCRM 实现的同一个 FastStack 服务(通过 FastStack 运行 Apache 和 MySql)中在我的桌面上部署 Joomla 吗?如果是这样怎么办?

jquery - 无法让 jQuery Waypoints 工作

php - 如何使用链接输出的替代布局覆盖 mod_menu 的模板?

templates - 将 Joomla 2.5 模板转换为 3.0

PayPal IPN 无法在沙箱中工作

php - Joomla 下拉菜单