Magento Forum

   
How to override Controller
 
Awesemo
Jr. Member
 
Total Posts:  7
Joined:  2010-04-11
 

How can I override this controller action? Mage_Adminhtml_Controller_Sales_Creditmemo
- viewAction

 
Magento Community Magento Community
Magento Community
Magento Community
 
MagePsycho
Moderator
 
Avatar
Total Posts:  1702
Joined:  2009-06-23
 

FYI, overriding controller is bit different than overriding of Block, Model & Helper classes.
You can use the following xml syntax for the purpose:

<config>
    <
frontend[1]
        
<routers>
            <
checkout[2]
                
<args>
                    <
modules>
                        <
yourModule before="Mage_Checkout">Namespace_Module_Overwrite_Checkout</yourModule[3]
                    
</modules>
                </
args>
            </
checkout>
        </
routers>
    </
frontend>
</
config>
[1] Depending on the controllers area ,"frontend" or “admin”
[2] Router node of the module to be overridden (look it up in the config.xml of that module)
[3] The tag <yourModule> can be anything, it must be unique within the <modules> node.
Your_Module_Overwrite_Checkout (is mapped to directory)
Your/Module/controllers/Overwrite/Checkout/

 
Magento Community Magento Community
Magento Community
Magento Community
 
Awesemo
Jr. Member
 
Total Posts:  7
Joined:  2010-04-11
 

Thanks for the reply. I already knew how to override controller but I just wanted to know how can I override controllers under the Controller folder “Mage/Adminhtml/Controller/Sales/Creditmemo.php”. Usually I do the following to override a controller.

<?php 
require_once("Mage/Adminhtml/Controller/Sales/Creditmemo.php");
class 
MyNamespace_Adminhtml_Controller_Sales_Creditmemo extends Mage_Adminhtml_Controller_Sales_Creditmemo{
 
...
}

but I cant override using this method for the file Mage_Adminhtml_Controller_Sales_Creditmemo which is under the Mage/Adminhtml/Controller/Sales/Creditmemo.php.

Regards.

 
Magento Community Magento Community
Magento Community
Magento Community
 
MagePsycho
Moderator
 
Avatar
Total Posts:  1702
Joined:  2009-06-23
 

I have never worked on the overriding of class under Controller/* folder. Simple way of doing will be copying that file and putting under app/code/local with the same folder structure.

Let us know if that works for you. At least this will be a new things for us to learn smile

(y)

 
Magento Community Magento Community
Magento Community
Magento Community
 
tzyganu
Mentor
 
Avatar
Total Posts:  2205
Joined:  2009-11-18
Bucharest, Romania
 

Overriding a class from the ‘Controller’ folder won’t help you at all.
These are never instantiated. They are just there as parent class for other controllers, to avoid duplicate some methods.
If you override them then the controllers called by the application (the ones in ‘controllers’ folder) will still extend the original class that you override. => no effect.

The best think you can do is to copy the class from ‘Controller’ folder in you local folder.
Here is an example.
/app/code/core/Mage/Adminhtml/Controller/Sales/Creditmemo.php => /app/code/local/Mage/Adminhtml/Controller/Sales/Creditmemo.php

and modify the copy to fit your needs.
By default Magento looks for a class in the local folder first instead of ‘core’ folder.

The downside of this is that on any future upgrades if there will be any modifications in the original ‘core’ file they will not be available for you.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Awesemo
Jr. Member
 
Total Posts:  7
Joined:  2010-04-11
 

Thanks guys for the quick and informative response.

 
Magento Community Magento Community
Magento Community
Magento Community
 
raghua
Jr. Member
 
Total Posts:  4
Joined:  2011-04-10
 

Hai Awesemo

was you able to get the output.i too facing the same problem.
i have to override magento\app\code\core\Mage\Cms\Controller\Router.php
i have pasted the file in : magento\app\code\community\Module\folder\controllers\Mage\Cms\Controller\Router.php
and also i am using community instead of local.dont know how to proceed.if someone knows please reply......

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top