Magento: Attempting to override a controller

流过昼夜 提交于 2019-12-11 04:23:27

问题


So I am trying to override the core CustomerController massDelete action. This is what I have so far:

config.xml

<frontend>
  <routers>
    <customer_massdelete>
      <args>
        <modules>
          <MyModule_MyExtension before="Mage_Adminhtml">MyModule_MyExtension</MyModule_MyExtension>
        </modules>
      </args>
    </customer_massdelete>
  </routers>
</frontend>

My Controller:

app/code/local/MyModule/MyExtension/controllers/CustomerController.php

<?php
require_once 'Mage/Adminhtml/controllers/CustomerController.php';
class MyModule_MyExtension_CustomerController extends Mage_Adminhtml_CustomerController {
  public function massDeleteAction() { 
   die('my controller');
  }
}

Yet when i run a mass delete the die that i put in their controller is run instead. Any ideas?

UPDATE:

Tried out solution as follows:

<config>
  <admin>
    <routers>
      <adminhtml>          
        <args>
          <modules>
            <MyModule_MyExtension before="Mage_Adminhtml">MyModule_MyExtension</MyModule_MyExtension>
          </modules>
        </args>
      </adminhtml>
    </routers>
  </admin>
</config>

Still nothing...

UPDATE 2:

My final config.xml was like this:

<config>
  <admin>
    <routers>
      <adminhtml>      
        <args>
          <modules>
            <Mymodule_Myextension before="Mage_XmlConnect_Adminhtml">Mymodule_Myextension</Mymodule_Myextension>
          </modules>
        </args>      
      </adminhtml>
    </routers>
  </admin>
</config>

However, if I have before="Mage_XmlConnect_Adminhtml" then I get some override issues when trying to go to most index pages. However if I go any lower in priority it doesn't override. So I am stuck again.


回答1:


i guess your config.xml is false, you might try:

<admin>
   <routers>
      <adminhtml>
         <args>
           <modules>
             <MyModule_MyExtension before="Mage_Adminhtml">MyModule_MyExtension</MyModule_MyExtension>
           </modules>
         </args>
      </adminhtml>
   </routers>
</admin>

reference: http://prattski.com/2010/06/24/magento-overriding-core-files-blocks-models-resources-controllers/




回答2:


So after a lot of research I finally figured out the issue. My issue was with the before="Mage_Adminhtml" in config.xml. Due to the way enterprise works it was not enough to override the top level class.

I used print_r(Mage::getConfig()->getNode('admin/routers/adminhtml'), true) to figure out all the modules overriding it and worked through the list. Mage_XmlConnect_Adminhtml was the last class that overrode this method before enterprise methods.

My final config.xml was like this:

<config>
  <admin>
    <routers>
      <adminhtml>      
        <args>
          <modules>
            <Mymodule_Myextensionbefore="Mage_XmlConnect_Adminhtml">Mymodule_Myextension</Mymodule_Myextension>
          </modules>
        </args>      
      </adminhtml>
    </routers>
  </admin>
</config>

It now works perfectly (Edit: Nope it doesnt...see comment below)



来源:https://stackoverflow.com/questions/16483967/magento-attempting-to-override-a-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!