Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    7

    Post How to overload a controller

    How to overload a controller in magento .?

  2. #2
    Registered User
    Join Date
    Apr 2011
    Posts
    8
    In this example we’re overloading Mage_Checkout_CartController::indexAction().
    1. Create your module folders and files
    1. Magento/app/code/local/MyNameSpace/MyModule/etc/config.xml
    2. Magento/app/code/local/MyNameSpace/MyModule/controllers/Checkout/CartController.php
    3. Magento/app/etc/modules/MyNameSpace_All.xml
    2. Edit /etc/config.xml
    Go to Magento/app/code/local/MyNameSpace/MyModule/etc/config.xml and paste the following xml into it (comments I’m not a 100% sure about are ending with “(?)”):
    1. <?xml version="1.0"?>
    2. <config>
    3. ***** ***** <modules>
    4. ***** ***** ***** ***** <MyNameSpace_MyModule>
    5. ***** ***** ***** ***** ***** ***** <version>0.1.0</version>
    6. ***** ***** ***** ***** </MyNameSpace_MyModule>
    7. ***** ***** </modules>
    8. ***** ***** <global>
    9. ***** ***** ***** ***** <!-- This rewrite rule could be added to the database instead -->
    10. ***** ***** ***** ***** <rewrite>
    11. ***** ***** ***** ***** ***** ***** <!-- This is an identifier for your rewrite that should be unique -->
    12. ***** ***** ***** ***** ***** ***** <!-- THIS IS THE CLASSNAME IN YOUR OWN CONTROLLER -->
    13. ***** ***** ***** ***** ***** ***** <mynamespace_mymodule_checkout_cart>
    14. ***** ***** ***** ***** ***** ***** ***** ***** <from><![CDATA[#^/checkout/cart/#]]></from>
    15. ***** ***** ***** ***** ***** ***** ***** ***** <!--
    16. ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** - mymodule matches the router frontname below
    17. ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** - checkout_cart matches the path to your controller
    18. ***** ***** ***** ***** ***** ***** ***** ***** ***** *****
    19. ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** Considering the router below, "/mymodule/checkout_cart/" will be
    20. ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** "translated" to "/MyNameSpace/MyModule/controllers/Checkout/CartController.php" (?)
    21. ***** ***** ***** ***** ***** ***** ***** ***** -->
    22. ***** ***** ***** ***** ***** ***** ***** ***** <to>/mymodule/checkout_cart/</to>
    23. ***** ***** ***** ***** ***** ***** </mynamespace_mymodule_checkout_cart>
    24. ***** ***** ***** ***** </rewrite>
    25. ***** ***** </global>
    26. ***** ***** <!--
    27. ***** ***** If you want to overload an admin-controller this tag should be <admin> instead,
    28. ***** ***** or <adminhtml> if youre overloading such stuff (?)
    29. ***** ***** -->
    30. ***** ***** <frontend>
    31. ***** ***** ***** ***** <routers>
    32. ***** ***** ***** ***** ***** ***** <mynamespace_mymodule>
    33. ***** ***** ***** ***** ***** ***** ***** ***** <!-- should be set to "admin" when overloading admin stuff (?) -->
    34. ***** ***** ***** ***** ***** ***** ***** ***** <use>standard</use>
    35. ***** ***** ***** ***** ***** ***** ***** ***** <args>
    36. ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** <module>MyNameSpace_MyModule</module>
    37. ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** <!-- This is used when "catching" the rewrite above -->
    38. ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** <frontName>mymodule</frontName>
    39. ***** ***** ***** ***** ***** ***** ***** ***** </args>
    40. ***** ***** ***** ***** ***** ***** </mynamespace_mymodule>
    41. ***** ***** ***** ***** </routers>
    42. ***** ***** </frontend>
    43. </config>
    3. Edit /controllers/Checkout/CartController.php
    Paste the following php code into Magento/app/code/local/MyNameSpace/MyModule/controllers/Checkout/CartController.php (the only change we’re doing to the indexAction() is adding an error_log() message):
    1. <?php
    2. # Controllers are not autoloaded so we will have to do it manually:
    3. require_once 'Mage/Checkout/controllers/CartController.php';
    4. class MyNameSpace_MyModule_Checkout_CartController extends Mage_Checkout_CartController
    5. {
    6. ***** ***** # Overloaded indexAction
    7. ***** ***** public function indexAction()
    8. ***** ***** {
    9. ***** ***** ***** ***** # Just to make sure
    10. ***** ***** ***** ***** error_log('Yes, I did it!');
    11. ***** ***** ***** ***** parent::indexAction();
    12. ***** ***** }
    13. }
    Last edited by mtthwsmith8; 10-29-2013 at 08:33 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

  Find Web Hosting      
  Shared Web Hosting UNIX & Linux Web Hosting Windows Web Hosting Adult Web Hosting
  ASP ASP.NET Web Hosting Reseller Web Hosting VPS Web Hosting Managed Web Hosting
  Cloud Web Hosting Dedicated Server E-commerce Web Hosting Cheap Web Hosting


Premium Partners:


Visit forums.thewebhostbiz.com: to discuss the web hosting business, buy and sell websites and domain names, and discuss current web hosting tools and software.