本文介绍了扩展magento核心控制器(Checkout / OnepageController)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我在覆盖核心控制器时遇到问题。我想添加一个新的函数,但它只能工作,如果我在核心文件(代码/核心/ checkout / controllers / onepagecontroller.php)。 后来一些职位,但它不工作。其中有些是: http://www.magentocommerce.com/boards/viewthread/32979/P0/ http://www.webspeaks.in/2011/03/override-controllers-in-magento.html www.magentocommerce.com/wiki/5 _-_ modules_and_development / 0 _-_ module_development_in_magento / how_to_overload_a_controller (我无法添加更多链接,对不起) 我不知道发生了什么...也许你可以帮助我。 p> 我使用magento 1.5,我有这3个文件: local - > Arias - > CoreExtended - > etc - > config.xml <?xml version =1.0 encoding =UTF-8?> < config> < modules> < Arias_CoreExtended> < version> 0.1.0< / version> < / Arias_CoreExtended> < / modules> < frontend> < routers> < checkout> < args> < modules> < Arias_CoreExtended before =Mage_Checkout> Arias_CoreExtended_Checkout< / Arias_CoreExtended> < / modules> < / args> < / checkout> < / routers> < / frontend> < / config> app - > etc - > modules - > Arias_CoreExtended .xml <?xml version =1.0?> < config> < modules> < Arias_CoreExtended> < active> true< / active> < codepool> local< / codepool> < / Arias_CoreExtended> < / modules> < / config> local - > Arias - > CoreExtended - > controllers - > Checkout - > OnepageController.php <?php require_once'Mage / controller / OnepageController.php'; class Arias_CoreExtended_Checkout_OnepageController extends Mage_Checkout_OnepageController { public function collectAction() { echo'WTF?'; } public function indexAction() { echo此控制器已被覆盖。 } } 预先感谢您的时间, 解决方案我将首先镜像你覆盖的控制器的相同目录结构,因此在这种情况下更改: local / Arias / CoreExtended / controllers / Checkout / OnepageController.php 至 local / Arias / CoreExtended / controllers / OnepageController.php 您应该小写您的命名空间/模块名称,您需要删除 _Checkout ,因为它覆盖控制器,查找模块中存在的任何内容,如果不回退到标准,则使用它们。正确的代码为: < arias_coreextended before =Mage_Checkout> Arias_CoreExtended< / arias_coreextended& 我已经使用这个确切的设置成功覆盖Onepage控制器! I am having problems while overriding a core controller. I want to add a new function but it only works if I do it in the core file (code/core/checkout/controllers/onepagecontroller.php).I have followed some post, but it's not working. Some of them are:http://www.magentocommerce.com/boards/viewthread/32979/P0/http://www.webspeaks.in/2011/03/override-controllers-in-magento.htmlwww.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/how_to_overload_a_controller(I can't add more links, sorry)I don't know what is happening... maybe you can help me ;).I'm using magento 1.5 and I have this 3 files:local -> Arias -> CoreExtended -> etc -> config.xml<?xml version="1.0" encoding="UTF-8"?><config> <modules> <Arias_CoreExtended> <version>0.1.0</version> </Arias_CoreExtended> </modules> <frontend> <routers> <checkout> <args> <modules> <Arias_CoreExtended before="Mage_Checkout">Arias_CoreExtended_Checkout</Arias_CoreExtended> </modules> </args> </checkout> </routers> </frontend></config>app -> etc -> modules -> Arias_CoreExtended.xml<?xml version="1.0"?><config> <modules> <Arias_CoreExtended> <active>true</active> <codepool>local</codepool> </Arias_CoreExtended> </modules></config>local -> Arias -> CoreExtended -> controllers -> Checkout -> OnepageController.php<?phprequire_once 'Mage/Checkout/controllers/OnepageController.php';class Arias_CoreExtended_Checkout_OnepageController extends Mage_Checkout_OnepageController{ public function collectAction() { echo 'WTF?'; } public function indexAction() { echo "This controller has been overridden."; }}Thanks in advance for your time, regards. 解决方案 I would first mirror the same directory structure of the controller you are overwriting, so in this case change: local/Arias/CoreExtended/controllers/Checkout/OnepageController.php to local/Arias/CoreExtended/controllers/OnepageController.phpYou should lowercase your namespace/module name and you need to remove _Checkout as it is overwriting the controllers in general, and will look up any that exist in the module to use them instead if not fall back to standard. The correct code would be:<arias_coreextended before="Mage_Checkout">Arias_CoreExtended</arias_coreextended>I have used this exact setup with success to overwrite the Onepage controller! 这篇关于扩展magento核心控制器(Checkout / OnepageController)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-17 05:04