Often if I want to use the URL helper outside of the context of a controller or action helper, I just create a new instance of the helper myself.
You should be able to use the following code to get a URL helper and use it:
$urlHelper = new Zend_Controller_Action_Helper_Url();
$url = $urlHelper->url(array('controller' => 'foo',
'action' => 'bar',
'module' => 'mod'));
I'm not sure why you are encountering that error, but if the helper has not yet been registered with the Front Controller (maybe you are calling this too early on in your application dispatch?), try using getStaticHelper()
instead of getExistingHelper()
:
$urlHelper = Zend_Controller_Action_HelperBroker::getStaticHelper('url');
If the URL helper is not yet registered with the plugin loader, it will register and load it for you.
From The Helper Broker Documentation:
There are also two static methods for retrieving helpers from the
helper broker: getExistingHelper()
and getStaticHelper()
.
getExistingHelper()
will retrieve a helper only if it has previously
been invoked by or explicitly registered with the helper broker; it
will throw an exception if not. getStaticHelper()
does the same as
getExistingHelper()
, but will attempt to instantiate the helper if has
not yet been registered with the helper stack. getStaticHelper()
is a
good choice for retrieving helpers which you wish to configure.