For helpful resources on overriding Magento controllers, blocks, models, helpers, etc. see Josh Pratt's post on Magento: Overriding Core Files (Blocks, Models, Resources, Controllers)
Here's a list of search results that I've found most helpful; otherwise good luck with the Googling!
<!-- in your app/code/local/etc/config.xml file -->
<config>
<admin>
<routers>
<adminhtml>
<args>
<modules>
<My_Module before="Mage_Adminhtml">My_Module</My_Module>
</modules>
</args>
</adminhtml>
</routers>
</admin>
</config>
And don't forget to include_once
or require_once
the parent controller!
<?php
// explicitly require parent controller b/c controllers are not autoloaded
require_once(Mage::getModuleDir('controllers','Mage_Adminhtml') .DS. 'Catalot' .DS. 'Product' .DS. 'AttributeController.php');
class My_Module_Adminhtml_Catalog_Product_AttributeController extends Mage_Adminhtml_Catalog_Product_AttributeController
{
...
}
In this example, the community module will be the Xtento_GridActions
module and specifically the Xtento_GridActions_Adminhtml
controllers.
<!-- in your app/code/local/etc/config.xml file -->
<config>
<admin>
<routers>
<adminhtml>
<args>
<modules>
<My_Module before="Xtento_GridActions_Adminhtml">My_Module_Adminhtml</My_Module>
</modules>
</args>
</adminhtml>
</routers>
</admin>
</config>
And don't forget to include_once
or require_once
the parent controller!
<?php
// explicitly require parent controller b/c controllers are not autoloaded
require_once(Mage::getModuleDir('controllers','Xtento_GridActions') .DS. 'Adminhtml' .DS. 'Gridactions' .DS. 'PrintController.php');
class My_Module_Adminhtml_Gridactions_PrintController extends Xtento_GridActions_Adminhtml_GridActions_PrintController
{
...
}
See this awesome Stack Overflow response from benmarks
test.php
<?php
# test.php => (http://mysite.dev/test.php)
ini_set('display_errors',1);
error_reporting(E_ALL^E_STRICT);
include 'app/Mage.php';
Mage::setIsDeveloperMode(true);
Mage::app();
// ===================================================================================================
// FIRST TEST - check if your module is loading correctly
// ===================================================================================================
// replace `COMMUNITY_MODULE` with the module you are looking to override
require_once Mage::getModuleDir('controllers','COMMUNITY_MODULE') . DS . 'path/to/CONTROLLER_NAME.php';
// replace `MY_MODULE` with the module you are looking to override
require_once Mage::getModuleDir('controllers','MY_MODULE') . DS . 'path/to/CONTROLLER_NAME.php';
$controller = new MY_MODULE_CONTROLLER_NAME(
Mage::app()->getRequest(), // required constructor arg
Mage::app()->getResponse() // required constructor arg
);
echo get_class($controller);
// ===================================================================================================
// END FIRST TEST - check if your module is loading correctly
//
// Visit yoursite.com/test.php and you should see your controller class name.
// If you see an error, or you see nothing, something fairly low-level is broken.
// If the error message is unintuitive, check that your module config is being
// merged and move from there.
//
// If the class instantiates, we know the following:
//
// + Base module config is good
// + File structure is appropriate for the config
// + The explicit include is good
// ===================================================================================================
// ===================================================================================================
// SECOND TEST - sniff for controller rewrites
// ===================================================================================================
// you can change 'standard' to 'admin' if you're debugging adminhtml controller rewrites
$router = Mage::app()->getFrontController()->getRouter('standard');
/* @var $router Mage_Core_Controller_Varien_Router_Standard */
$reflection = new ReflectionClass($router);
$modules = $reflection->getProperty('_modules');
$modules->setAccessible(true);
echo "<pre>";
print_r($modules->getValue($router));
echo "</pre>";
// ===================================================================================================
// END SECOND TEST - sniff for controller rewrites
// ===================================================================================================
The second test should output something similar to the below example:
Array
(
[manage] => Array
(
[0] => Mage_Index_Adminhtml
[1] => Mage_Paygate_Adminhtml
[2] => Mage_Paypal_Adminhtml
[3] => Mage_Widget_Adminhtml
[4] => Mage_Oauth_Adminhtml
[5] => Mage_Authorizenet_Adminhtml
[6] => Mage_Bundle_Adminhtml
[7] => Mage_Centinel_Adminhtml
[8] => Mage_Compiler_Adminhtml
[9] => Mage_Connect_Adminhtml
[10] => Mage_Downloadable_Adminhtml
[11] => Mage_ImportExport_Adminhtml
[12] => Mage_Api2_Adminhtml
[13] => Mage_PageCache_Adminhtml
[14] => Mage_XmlConnect_Adminhtml
[15] => Ash_Slideshow_Adminhtml
[16] => Ash_Up_Adminhtml
[17] => Bubble_Launcher_Adminhtml
[18] => EM_Megamenupro_Adminhtml
[19] => Ebizmarts_AbandonedCart_Adminhtml
[20] => Ebizmarts_MageMonkey_Adminhtml
[21] => Ebizmarts_Mandrill_Adminhtml
[22] => Fishpig_Wordpress_Adminhtml
[23] => Fooman_Common_Adminhtml
[24] => Fooman_PdfCustomiser_Adminhtml
[25] => Infomodus_Upslabel_Adminhtml
[26] => Webtex_Giftcards_Adminhtml
[27] => Pan_Authorizenetcim
[28] => Pan_Gridactions_Adminhtml
[29] => Xtento_GridActions_Adminhtml
[30] => Xtento_OrderExport_Adminhtml
[31] => Mage_Adminhtml
[32] => Phoenix_Moneybookers
[33] => Mage_Captcha_Adminhtml
[34] => Mage_CurrencySymbol_Adminhtml
)
... MORE MODULES (excluded for brevity) ...
[upslabel] => Array
(
[0] => Pan_Infomodusupslabel
[1] => Infomodus_Upslabel
)
[giftcards] => Array
(
[0] => Pan_Giftcards
[1] => Webtex_Giftcards
)
[orderedit] => Array
(
[0] => Pan_OrderEdit
[1] => TinyBrick_OrderEdit
)
[gridactions] => Array
(
[0] => Pan_Gridactions
[1] => Xtento_GridActions
)
)
Wherever you see more than one subarray, there is a controller directory rewrite.