JOOMLA 3.x 如何在 if 检查后隐藏模板

JOOMLA 3.x How to hide a template after if check

我正在尝试理解 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');
    }
}

这非常有效,但我希望在检查 return 是否为 NULL 之后我想隐藏显示 default.php 并仅显示 JText 上的消息.

我该怎么做?

为了您的目的,您只需 return 来自 model 函数的 $value 并在 view.html.phpdisplay() 函数中调用该函数。

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');
} ?>