我正在尝试了解Joomla语言,并且遇到这种情况:
在models/calcoloonline.php
中,我具有此功能
public function estraivariabili()
{
$db = JFactory::getDBO();
// Put the result into a variable first, then return it.
$value = $db->setQuery("SELECT * FROM #__calcolo_imposte")->loadObjectList();
if ($value != NULL)
{
return $value;
}
else
{
return JFactory::getApplication()->enqueueMessage(JText::_('COM_CALCOLO_IMPOSTE_IMPORTI_NON_DEFINITI'), 'type');
}
}
这很好用,但是我想在检查返回值是否为NULL
之后,我想隐藏显示default.php
并仅在JText
上显示消息。
我该怎么做?
出于您的目的,您只需从$value
函数返回model
并在view.html.php
的display()
函数中调用该函数。
在default.php
文件中,检查$value
的可用性并显示您的内容。
例如,您将数据存储在view.php.html
。看起来像
public function display($tpl = null)
{
$model = $this->getModel();
$this->value = $model->estraivariabili();
return parent::display($tpl);
}
您的default.php
文件为
<?php if (!empty($this->value)) { ?>
<h1>The value is not empty.</h1>
<?php } else {
// value not found :(
JFactory::getApplication()->enqueueMessage(JText::_('NOT_FOUND_MESSAGE'), 'warning');
} ?>