Change default controller in Magento

I created modules:

app/code/local/MyStore/Welcome

And in this module I have a controller like:

MyStore_Welcome_IndexController

From my current knowledge, I see the beginning of the Magento load Mage_Cms_IndexController controller as the default controller.

Now I want to load the default MyStore_Welcome_IndexController controller.

How can i do this?


Update:

I found a way to do this using the admin function: From the menu that you selected: System / Configuration / Web: You still select: "Default page" => "Default web address" to enter the module: Image to show how to config

+4
source share
2 answers

You need to make sure your controller extends Mage_Cms_IndexController and then override this default controller using the controller overload method. In this method, you will create the plugin as usual, but you need to do the following:

  • add a require_once() declaration at the top with the relative path to the controller that you are overloading. For instance.

     require_once 'Mage/Checkout/controllers/OnepageController.php'; class MyClass_OverloadedCheckout_Checkout_OnepageController extends Mage_Checkout_OnepageController 
  • Create any methods or class properties that you can add in addition to the default.

  • in your config.xml file add the following lines outside the <global> node:

      <frontend> <routers> <myclass_overloadedcheckout> <use>standard</use> <args> <module>Myclass_OverloadedCheckout</module> <frontName>OverloadedCheckout</frontName> </args> </myclass_overloadedcheckout> </routers> </frontend> 

Something to remember - if you are rewriting any default methods, you need to return parent::{methodname} before or after the functions you enter to make sure that the default behavior continues to work.

+3
source

You should think again if you really want to do this because it is a huge change, but you can simply override Mage_Cms_IndexController . How you can override the controller, you can find, for example. here .

In any case, I would try to solve the problem differently. Perhaps you can use the Event / Observer pattern?

+1
source

All Articles