Zend Framework:如何从视图脚本调用控制器操作助手?
我有一个自定义控制器操作助手,我希望能够从视图脚本调用它。我怎样才能实现这个目标?
解决方案:
警告:您可能并不真的想从视图脚本中调用操作助手,除非您不使用任何调度挂钩。但如果你真的、真的想要调用你的动作助手:
$helper = Zend_Controller_Action_HelperBroker::getStaticHelper('Myhelper');
I have a custom controller action helper that I would like to be able to call from a view script. How can I achieve this?
Solution:
Warning: You probably don't really want to call an action helper from your view script unless you aren't using any dispatch hooks. But if you really, really want to call your action helper:
$helper = Zend_Controller_Action_HelperBroker::getStaticHelper('Myhelper');
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯,你不能,也不应该不这就是 MVC。尝试解决此类问题应该是对您的设计的潜在警告。
但是,在某些情况下您可能需要实现类似的目标。
例如,flashMessenger() 操作助手旨在提供一种在请求之间共享消息的简单方法,但是它在视图中不可用,您需要手动将其传递到视图。我自己编写了一个包装器,可以用作视图助手。
因此,也许尝试更明确地说明您想要实现的目标,我们可以帮助您了解是否没有好的替代方案。
Afaik, you can't, and you should not that's MVC. Trying to solve such problem should be a potential warning on your design.
However, in some case you may need to achieve a similar thing.
For example, the flashMessenger() action helper aims to provide a simple way to share messages between requests, however it is not available in the view, you need to manually pass it to the view. I've myself written a wrapper to be able to use as a view helper.
So maybe try to be more explicit on what you're trying to achieve, and we may help you to know if there isn't a good alternative.