Search This Blog

Loading...

Feb 24, 2011

How to Request Magento Controller, Router, Action and Module Name

In order to make a customization in Magento, developer must consider the following code to request the Module Name, Router Name, Action Name and Controller Name. Request for these names are important in debugging stage, customization or maintenance especially when you're not using a developer toolbar to track the magento file path.




/*** get Controller name
 */
$this->getRequest()->getControllerName();
 

Controller Name - Each Module with Controllers has a special folder named 'controllers' which contains all the Controllers for a module. In the above example, the URL portion category is translated into the Controller file.

/**
 * get Action name, i.e. the function inside the controller
 */
$this->getRequest()->getActionName();
 

Action Name - The action method name that specified in every controller For example, this is "view". The word "view" is used to create the Action Method. So, in our example, "view" would be turned into "viewAction".

class Mage_Catalog_CategoryController extends Mage_Core_Controller_Front_Action
{
    public function viewAction()
    {
        //main entry point
    }
}



/**
 * get Router name
 */
$this->getRequest()->getRouteName();


Router Name - the code return the a routing name if there is no valid Controller / Action Name. It simply tell the path which you are routing with.

/**
 * get module name
 */
$this->getRequest()->getModuleName();

Module Name - the output will be the Module name where the page is located.

Take Note: If you're editing in Class File the $this may not work. You can try the following code to get the above request.

# get Controller name
Mage::app()->getRequest()->getControllerName();

# get Action name, i.e. the function inside the controller
Mage::app()->getRequest()->getActionName();

# get Router name
Mage::app()->getRequest()->getRouteName();

# get module name
Mage::app()->getRequest()->getModuleName();

2 comments:

terrylittrell said...

Thanks for sharing about magento Controller. now a days magento ecommerce is providing in many more company it's having more demand and easy to handle. it's reaching very fast.


magento development

portable wireless router said...

great, it really helps someone like me who is not a very computer literate person.