Zend 框架:控制器插件与动作助手 [英] Zend Framework: Controller Plugins vs Action Helpers

查看:32
本文介绍了Zend 框架:控制器插件与动作助手的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以提供一些提示和/或示例控制器插件和动作助手有何不同吗?是否存在可以用一个而不是另一个来完成特定任务的情况?对我来说,它们看起来或多或少相同,我经常在决定何时使用什么时遇到麻烦......有什么大的不同吗?

Could someone give few tips and/or examples how Controller Plugins and Action Helpers are different? Are there situations where particular task could be accomplished with one but not another? For me they both look more or less the same and I'm often having trouble having to decide when to use what... Are there any big differences?

推荐答案

控制器插件可以在路由过程中的任何点(preDispatch postDispatch、routeStartup、routeShutdown)挂钩到任何控制器,这使得它们能够提供幕后功能,例如ACL 强制执行.

Controller plugins can hook into any controller at any point in the routing process (preDispatch postDispatch, routeStartup, routeShutdown) which makes them apt at providing behind the scenes functionality like ACL enforcement.

Action Helpers 用于控制器可能需要访问的可重用但可选的段(重定向器、flashMessenger).

Action Helpers are for for reusable but optional segments that your controller might need to access (redirector, flashMessenger).

因此,如果您要创建始终需要自行执行的可重用代码片段,请使用控制器插件,否则您可能需要一个动作助手.

So if you are creating a reusable snippet of code that always needs to execute itself then use a controller plugin, otherwise you probably want an action helper.

这篇关于Zend 框架:控制器插件与动作助手的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆