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)
.
Asked
Active
Viewed 7,294 times
4

Sonny
- 8,204
- 7
- 63
- 134
1 Answers
5
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);
}

Aron Rotteveel
- 81,193
- 17
- 104
- 128
-
Interesting! I looks like `getHelper()` isn't used internally. I wonder why it's recommended. – Sonny Mar 11 '11 at 14:58
-
1@Sonny, it's not really not recommended; `_helper` is easier to type and read and is often preferred over the explicit `getHelper()` syntax. A benefit of using `getHelper()`, though, is that you automatically have intellisense support in your editor, where you would not have it when using the `_helper` magic getter. Personally, I prefer readability over intellisense, and use `_helper` :) – Aron Rotteveel Mar 11 '11 at 15:02
-
1Also getHelper is complement to setHelper ;) Which can be IMO used to register Helpers with fancy prefixes you don't want to have in your helper search path... – Tomáš Fejfar Mar 11 '11 at 19:20