Magento:如何覆盖Mage_Core_Controller_Front_Action [英] Magento: How to Override Mage_Core_Controller_Front_Action
问题描述
我想覆写 Mage_Core_Controller_Front_Action
,为所有前端控制器操作添加ACL检查,类似于在中执行的方式Mage_Adminhtml_Controller_Action: :preDispatch()
使用 Mage_Adminhtml_Controller_Action :: _ isAllowed()
。
I'd like to override Mage_Core_Controller_Front_Action
to add ACL checks to all front-end controller actions, similar to the way it's done in Mage_Adminhtml_Controller_Action::preDispatch()
using Mage_Adminhtml_Controller_Action::_isAllowed()
.
能够创建成功扩展 Mage_Core_Controller_Front_Action
,包含并从任何控制器使用它的 PackageName_ModuleName_Controller_Front_Action
,但是,此方法将要求我现在扩展每个 Magento前端控制器,我想添加ACL,以使他们使用我的新Front_Action。如果我想要拒绝,允许优先级策略设置,这是很多重写。
I've been able to create a PackageName_ModuleName_Controller_Front_Action
that successfully extends Mage_Core_Controller_Front_Action
, include, and use it from any controller, however, this method would require that I now extend every Magento front-end controller that I want to add ACLs to in order to get them to use my new Front_Action. If I want a Deny, Allow priority policy setup, that's a lot of overriding.
如果任何人知道如何正确地扩展这个类更有效的方式,它一定会来在方便的情况下,否则我想我可以工作在允许,拒绝优先级,但这仍然将是很多重叠的我的用例。
If anyone knows how to properly extend this class in a more efficient manner it would certainly come in handy, otherwise I suppose I could work on an Allow, Deny priority, but that's still going to be a lot of overriding for my use case.
推荐答案
而不是重载 Mage_Core_Controller_Front_Action
(这是几乎不可能没有,如你所说,覆盖每个前面的控制器,基于这个类),你可以把一个观察者在 controller_action_predispatch
事件,并使用与它一起发送的 controller_action
值(实际上应该在前面 - 结束 Mage_Core_Controller_Front_Action
)的当前实例。
Instead of overriding Mage_Core_Controller_Front_Action
(which is almost impossible without, as you mentioned, overriding each front controller that is based on this class), you can put an observer on the controller_action_predispatch
event, and use the controller_action
value that is sent with it (and which should actually be on front-end the current instance of Mage_Core_Controller_Front_Action
).
这篇关于Magento:如何覆盖Mage_Core_Controller_Front_Action的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!