Search code examples
joomlahidedefault

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


I'm trying to understand Joomla language and I have this situation:

In a models/calcoloonline.php I have this function

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

This works perfectly but I'd like that after check if the return is NULL I want to hide display default.php and show only the message on JText.

How can I do this?


Solution

  • For your purpose, you just return the $value from the model function and call the function at view.html.php's display() function.

    At default.php file check the availability of the $value and show your contents.

    For example, you store the data at view.php.html. It looks like

    public function display($tpl = null)
    {
        $model = $this->getModel();
    
        $this->value = $model->estraivariabili();
        return parent::display($tpl);
    }
    

    And your default.php file would be

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