通常,如果我想使用的网址助手控制器或动作助手的背景之外,我刚刚创建帮助自己的新实例。
您应该可以使用下面的代码来获得一个网址助手,并使用它:
$urlHelper = new Zend_Controller_Action_Helper_Url();
$url = $urlHelper->url(array('controller' => 'foo',
'action' => 'bar',
'module' => 'mod'));
我不知道为什么你遇到这个错误,但如果助手尚未注册与前端控制器(?也许你正在调用这个太早在你的应用调度),请尝试使用getStaticHelper()
代替getExistingHelper()
:
$urlHelper = Zend_Controller_Action_HelperBroker::getStaticHelper('url');
如果URL助手尚未与插件加载注册,它将注册并加载它你呢。
从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.
我不知道你已经给了足够的信息来解决问题。你如何配置你的ZF应用程序?配置是什么样的?这只是一个URL,还是问题发生在你的默认模块的其他地方?它也发生在其他模块吗?您收到的异常是否也说明了HelperBroker正在查找的文件夹? – curtisdf 2012-07-25 19:51:16