joomla2.5joomla1.7joomla1.6

Is the setRedirect function works in the model file of a component


setRedirect doesn't works in the model file of a component.

models->test.php

$this->setRedirect(JRoute::_('index.php', false));

Solution

  • In Joomla 2.5 and Joomla 3.0

    Redirection inside a model file:

    $app = JFactory::getApplication();
    $app->redirect(JRoute::_(JURI::root().'index.php'));
    

    This redirection works in all files inside joomla, But the better way is to use in controller file is the below one.

    Redirection inside a controller file:

    $this->setRedirect(JRoute::_('index.php', false));
    

    In Joomla 1.6 and 1.7 use this for redirection inside model file:

    global $mainframe;
    $mainframe              =& JFactory::getApplication();
    $mainframe->redirect($url, JText::_('Your Mail sent') );