As I know there are two ways to override a controller class.

  1. Using from/to tags in config.xml

                        Considering the router below, "/mymodule/checkout_cart/" will be
                        "translated" to "/MyNameSpace/MyModule/controllers/Checkout/CartController.php" (?)
  2. Using 'before' keyword in config.xml

                                <mynamespace_mymodule before="Mage_Adminhtml">Mynamespace_Mymodule_Adminhtml</mynamespace_mymodule >

Can anyone explain what is the best way to override a controller or the above methodologies are using for different purposes of overriding. Any suggestions will be appreciated.

Thank you.

  • I usually use the second method but it's just a personal reference. In my opinion it's easier/ cleaner
    – Sander Mangel
    Sep 30 '13 at 9:20
  • Yes. I'm also using the second way. But there should be a reason to have two methodologies for the same task right?
    – Sukeshini
    Sep 30 '13 at 9:25
  • added my reply as answer 'cause it was getting a bit too long for a comment
    – Sander Mangel
    Sep 30 '13 at 9:34
  • Did you manage to resolve your question?
    – Sander Mangel
    Oct 1 '13 at 10:44
  • Not yet. I couldn't find a exact solution for this.
    – Sukeshini
    Oct 1 '13 at 10:45

The from/to rewrite is, in my opinion, there to make your extensions SEO friendly.

For example a 'brands' extension would rewrite from the default domain.com/brandsextension/index/list to a nice domain.com/brands/. Using it to reroute Magento core extensions to your own controller works fine but if it ever changes URL's from for example checkout/cart/ to checkout/shoppingcart it would break your extensions functionality.

I would suggest going with the second option since it is, as far as I know, more robust. But this is all opinion based so feel free to correct me ;)

  • I searched a lot. But nobody has mentioned why there are two functionalities to override magento controller. Some has mentioned whatever the method you like you can use. Some has mentioned if first one didn't work then use the second way. But these things cannot accept without any proof. Please be kind enough to provide proper explanation on this. Thanks all
    – Sukeshini
    Oct 1 '13 at 17:10
  • I'm not sure but this methods came with different magento versions or same version ?
    – Sukeshini
    Oct 1 '13 at 17:12
  • 1
    I've checked a few extensions out there and most use the second option. Using the first option to overwrite the controller really is a hack because it's supposed to be used for URL rewriting and not overwriting a controller. It so happens to be that you can use it for that but I would advice against is because of reasons previously stated
    – Sander Mangel
    Oct 2 '13 at 8:29
  • Yes by using the first way we can rewrite the URI as well.
    – Sukeshini
    Oct 2 '13 at 8:40

I have possibly found the reason behind 2 type of the controller overwrite procedure.

  • When you want to overwrite a controller and also want to change the default URL the use 1st procedure.

  • When you do not want to change the URL and only want to overwrite the controller then user the 2nd procedure.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.