Reputation: 83
So I normally have no problem using the "url" action helper from a custom action helper, when accessing a module, using the following:
$urlHelper = Zend_Controller_Action_HelperBroker::getExistingHelper('url');
But the following error occurs if the default module (the root url, /) is accessed:
Fatal error: Uncaught exception 'Zend_Controller_Action_Exception' with message 'Action helper "Url" has not been registered with the helper broker' in /home/erahhal/Code/ZendFramework-1.11.12/library/Zend/Controller/Plugin/Broker.php on line 336
What is the root of this problem?
Upvotes: 2
Views: 1592
Reputation: 69957
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()
andgetStaticHelper()
.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 asgetExistingHelper()
, 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.
Upvotes: 2