Change default controller in Magento
I have created a modules:
app/code/local/MyStore/Welcome
And in this module, I have a controller like:
MyStore_We开发者_如何学Pythonlcome_IndexController
From my current knowledge, I see at the beginning Magento
load Mage_Cms_IndexController
controller as the default controller.
Now I want to load MyStore_Welcome_IndexController
controller as default.
How can I do that?
Update:
I've found a way to do using admin feature: From the menu you chose: System/Configuration/Web: You continue to choose: "Default Page" => "Default Web URL" to field the module:
You need to make sure that your controller extends Mage_Cms_IndexController
and then override that default controller via the controller overloading method. In this method you will create a plugin as per usual, but you need to do the following:
add the declaration
require_once()
at the top with the relative path to the controller you're overloading. E.g. :require_once 'Mage/Checkout/controllers/OnepageController.php'; class MyClass_OverloadedCheckout_Checkout_OnepageController extends Mage_Checkout_OnepageController
Create any class methods or properties that you may want to add in addition to the default.
in your config.xml add the following lines outside of 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 rewrite any default methods you need to return parent::{methodname}
either before or after your injected functionality to ensure that the default behaviors continue to operate.
You should think again if you really want to do it because it is a huge change, but you could simply override the Mage_Cms_IndexController
. How you can override a controller, you can find e.g. here.
Anyway, I would try to solve the problem another way. Maybe you can use the Event/Observer Pattern?
精彩评论