Skip to main content

Q. Which ways exist in Magento to add router classes?

1.
<config>
<default>

<web>
<routers> <!– declare default routers–>
<your_custom_router>
<area>frontend</area>
<class>Yournamespace_Yourmodule_Controller_Router</class>
</your_custom_router>
</routers>

</web>

</default>

</config>

Then you should declare your module router in a normal way, using the parameter <use>your_custom_router</use> instead of “standard”.

2. using event observer
<config>
<global>
<events>
<controller_front_init_routers>
<observers>
<cms>
<class>Mage_Cms_Controller_Router</class>
<method>initControllerRouters</method>
</cms>
</observers>
</controller_front_init_routers>
</events>
</global>
</config>

then in observer class,
public function initControllerRouters($observer)
{
/* @var $front Mage_Core_Controller_Varien_Front */
$front = $observer->getEvent()->getFront();

$front->addRouter(‘cms’, $this);
}

By Michael Cristancho

I'm a Digital Commerce and Experience evangelist who enjoys engaging in thought-provoking conversation and mutual exploration. I am a strong believer that learning never ends, and each day brings another opportunity to grow as an individual and professional.