我们如何在 Joomla 2.5 视图中调用不同的模型及其功能?
型号:settings.php
// import Joomla modelitem library
jimport('joomla.application.component.modelitem');
class UrcModelSettings extends JModelItem
{
public function getSettings($user_id = '')
{
$user = JFactory::getUser();
$user_id=$user->id;
$db =& JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('*');
$query->from('#__settings_urc');
$query->where('user_id = '. (int) $user_id);
$db->setQuery($query);
return $db->loadObjectList();
}
}
查看:view.html.php
// import Joomla view library
jimport('joomla.application.component.view');
/**
* HTML View class for the HelloWorld Component
*/
class UrcViewUrc extends JView
{
// Overwriting JView display method
function display($tpl = null)
{
$model = $this->getModel('Settings');
$datas = $model->getSettings();
// Check for errors.
if (count($errors = $this->get('Errors')))
{
JLog::add(implode('<br />', $errors), JLog::WARNING, 'jerror');
return false;
}
// Display the view
$user = JFactory::getUser();
if($user->id!=0)
{
parent::display($tpl);
}
else
{
echo "You have not permission for this page";
}
}
}
我正在使用 getModel('Settings'); 它在控制器中工作,但它给了我一个错误的看法。
Notice: Undefined index: settings in C:\wamp\www\Joomla\libraries\joomla\application\component\view.php on line 413
Fatal error: Call to a member function getSettings() on a non-object in C:\wamp\www\Joomla\components\com_urc\views\urc\view.html.php on line 40