I am kinda in a pickle at the moment kinda tearing my head off. I am trying to override a controller method in the backend admin of Magento to allow some additional functionality. Here is the url path I am trying to apply my override. <Magento root path>/index.php/admin/iBanners_banner/edit/id/2/key/4c9796d89ba5e8847e4ce8c893cd6901/
Here is the admin fragment router xml for the original plugin that is present in their config.xml file.
<admin>
<routers>
<adminhtml>
<args>
<modules>
<ibanners before="Mage_Adminhtml">Fishpig_iBanners_Adminhtml</ibanners>
</modules>
</args>
</adminhtml>
</routers>
</admin>
Here is my controller class with the appropriate edit method that I need to override. This file is located in the following directory structure: app/code/local/Leafcutter/Ibanners/controllers/Adminhtml/Ibanners/BannerController.php
<?php
require_once("Fishpig/IBanners/controllers/Adminhtml/IBanners/BannerController.php");
class Leafcutter_iBanners_Adminhtml_iBanners_BannerController extends Fishpig_iBanners_Adminhtml_iBanners_BannerController
{
public function _construct(){
Mage::log('Using Leafcutter Extension');
parent::_construct();
}
public function editAction()
{
die('Leafcurtter has been returned');
}
}
As you would expect if you go to this edit url, my modified edit function should die with a message.
I also apply the what I thought were the appropriate bits of code for the admin fragment router xml in my extension's config.xml file. Now when I refresh the page or I log out and log back into to the backend. My extension's controller does not override the original controller and the original controller loads as if my version did not exist at all.
The following 2 fragments were sample of what I have attempted to override the original extension's controller both did not work but are an example of all of the unsuccessful attempts at getting this to work.
<admin>
<routers>
<adminhtml>
<args>
<modules>
<ibanners before="Mage_Adminhtml">Leafcutter_iBanners_Adminhtml</ibanners>
</modules>
</args>
</adminhtml>
</routers>
</admin>
<admin>
<routers>
<ibanners>
<args>
<modules>
<Leafcutter_iBanners before="Fishpig_iBanners">Leafcutter_iBanners_Adminhtml</Leafcutter_iBanners>
</modules>
</args>
</ibanners>
</routers>
</admin>
Unless if strictly it is impossible to override an extension's backend controller at all and my solution was flawed from the start, if someone can help me especially looking at my admin router code in my config xml then that would be great. Because I don't want to apply a hack to the original extension, which I may have to do if presented with absolutely no choice. Thanks in advance.
Override is probably the wrong word to use for replacing a controller class. It's better to think of these sorts of configurations as something like "adding a module's controllers as options for a particular URL route" With that in mind, there's X reasons this could go wrong.
Your configuration is wrong/incorrect
Magento finds a controller in the Fishpig module first.
Magento finds your configuration, but can't find a controller that's named correctly
The _validateControllerClassName
method in app/code/core/Mage/Core/Controller/Varien/Router/Standard.php
is a great place to start debugging these sorts of things. Some var_dump
debugging in there will tell you why Magento accepted or rejected a particular module's controller configuration (or if it never found it in the first place)
Try below
<admin>
<routers>
<adminhtml>
<args>
<modules>
<Leafcutter_Ibanners before="Fishpig_IBanners">Leafcutter_Ibanners</Leafcutter_Ibanners>
</modules>
</args>
</adminhtml>
</routers>
</admin>
For COntollers
require_once 'Fishpig/IBanners/controllers/Adminhtml/IBanners/BannerController.php';
class Leafcutter_IBanners_Adminhtml_Ibanners_BannerController extends Fishpig_IBanners_Adminhtml_IBanners_BannerController
{
protected function _construct()
{
die('it works');
}
}