Magento:如何覆盖 Mage_Core_Controller_Front_Action [英] Magento: How to Override Mage_Core_Controller_Front_Action

查看:22
本文介绍了Magento:如何覆盖 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().

我已经能够创建一个 PackageName_ModuleName_Controller_Front_Action,它成功地扩展了 Mage_Core_Controller_Front_Action,包括并从任何控制器使用它,但是,这个方法需要我现在扩展每个我想要添加 ACL 的 Magento 前端控制器,以便让它们使用我的新 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 值(实际上应该在前端 controller_action_predispatch 事件的当前实例代码>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屋!

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