【发布时间】:2013-01-31 09:23:53
【问题描述】:
在J!2.5 Tutorial 中,视图中只加载了一个模型(默认模型)。 J!1.5 中的片段不再与本教程中的技术一起使用。 这是我的扩展资料。 controller.php
function display($cachable = false)
{
// set default view if not set
$input = JFactory::getApplication()->input;
JRequest::setVar('view', JRequest::getCmd('view', 'HelloWorlds'));
// We will add a second model "bills"
$model = $this->getModel ( 'helloworlds' ); // get first model
$view = $this->getView ( 'helloworlds', 'html' ); // get view we want to use
$view->setModel( $model, true ); // true is for the default model
$billsModel = &$this->getModel ( 'mycomponents' ); // get second model
$view->setModel( $billsModel );
// call parent behavior
parent::display($cachable);
}
这是我的观点。 views/helloworlds.view.hml.php
function display($tpl = null)
{
// Get data from the model
$model = $this->getModel();
$items = $this->get('Items');
$pagination = $this->get('Pagination');
$model2 = &$this->getModel('mycomponents');
$items2 = $model2->get('Items');
$pagination2 = $model2->get('Pagination');
// Check for errors.
if (count($errors = $this->get('Errors')))
{
JError::raiseError(500, implode('<br />', $errors));
return false;
}
// Assign data to the view
$this->items = $items;
$this->pagination = $pagination;
$this->items2 = $items2;
$this->pagination2 = $pagination2;
// Display the template
parent::display($tpl);
}
但不幸的是,没有加载模型2。这里发生了什么? 我的错误在控制器中吗?是否在控制器中正确设置了两个模型? 那么我在视图中的代码呢?我必须以这种方式加载模型吗(从 J!1.5 已知)?
最好的问候 比约恩
【问题讨论】:
-
不知道为什么会翻倍。请给我可能重复的问题的链接。
标签: joomla2.5 joomla-extensions