Rewriting Controller vs. Adding New Controller to Existing Module in Magento 1

controllersmodulethird-party-module

I'm looking at a community extension called Ambassador_Affiliate, and it's doing something that I have not seen before. I'm not sure what it's doing, so I'd like to check with the community.

In config.xml, there is…

<frontend>
    <routers>
        <customer>
            <args>
                <modules>
                    <Ambassador_Affiliate before="Mage_Customer">Ambassador_Affiliate</Ambassador_Affiliate>
                </modules>
            </args>
        </customer>
    </routers>
</frontend>

In Ambassador/Affiliate/controllers/AffiliateController.php, there is…

<?php

class Ambassador_Affiliate_AffiliateController extends Mage_Core_Controller_Front_Action
{
…


}

It looks to me the Ambassador extension is adding a new controller, instead of rewriting, its own controller to the Mage_Customer module.

If it is so, why would you do this as opposed to just defining a entirely new controller under Ambassador_Affiliate (beside wanting to use the customer frontname of Mage_Customer)?

If it's not, what is it doing?

Best Answer

Magento checks all controllers whether the actionMethod exists, if this is the case, then it is executed.

The sorting order, can be defined via before and after

But using after makes no sense, if you ask me. If you want your controller to be executed, instead of the default one use before.

So if you want to kill all other actions, you can use your own frontName (with uppercase N!), if you only want to add one action, this is the right way.

Related Topic