Zend Controller Action: _redirect() vs getHelper('Redirector')->gotoUrl()

Sonny picture Sonny · Mar 11, 2011 · Viewed 7.2k times · Source

I've read that $this->getHelper('[helper_name]') is preferable to $this->_helper->[helper_name]. What I haven't been able to find any documentation of is which of these is better/preferred: $this->_redirect($url) or $this->getHelper('Redirector')->gotoUrl($url).

Answer

Aron Rotteveel picture Aron Rotteveel · Mar 11, 2011

Use whatever one suits you, they do exactly the same thing:

/**
 * Redirect to another URL
 *
 * Proxies to {@link Zend_Controller_Action_Helper_Redirector::gotoUrl()}.
 *
 * @param string $url
 * @param array $options Options to be used when redirecting
 * @return void
 */
protected function _redirect($url, array $options = array())
{
    $this->_helper->redirector->gotoUrl($url, $options);
}