So, I've written a custom router, in as much as I've extended Mage_Core_Controller_Varien_Router_Standard
and created my own match()
function. This part works beautifully, mapping the differently formatted URLs I'm using for a specific section of the site to the typical frontname/controller/action
pattern.
The only issue is I now cannot use getUrl()
in the normal way.
For example, the frontName in the modules config.xml is lookfor
, and the extension name is Customsearch
. Usually, using Mage::getUrl('customsearch/action')
would return me a url of lookfor/action
. But, with the custom router, I simply get back customsearch/action
. If I switch back to the standard router in the config.xml
, voila, it works.
You might ask why I want this when my URLs are different - handily some functionality through this module will still be accessed the normal way. I've got this to work as expected (by placing my custom code between the normal controller/action finding code, and the noRoute stuff), its simply the URL lookup thats failing.
I've done some digging, and noticed that in the below function, from Mage_Core_Model_Url
, the $this->_getData('route_front_name')
has the wrong frontName (customsearch
, rather than lookfor
), but I can't spot where this is set.
public function getRouteFrontName()
{
if (!$this->hasData('route_front_name')) {
$routeName = $this->getRouteName();
$route = Mage::app()->getFrontController()->getRouterByRoute($routeName);
$frontName = $route->getFrontNameByRoute($routeName);
$this->setRouteFrontName($frontName);
}
return $this->_getData('route_front_name');
}
Here're the relevant sections from the modules config.xml...
<frontend>
<routers>
<customsearch>
<use>namespace_customsearch</use>
<args>
<module>Namespace_Customsearch</module>
<frontName>lookfor</frontName>
</args>
</customsearch>
</routers>
...
</frontend>
...
<default>
<web>
<routers>
<namespace_customsearch>
<area>frontend</area>
<class>Namespace_Customsearch_Controller_Router</class>
</namespace_customsearch>
</routers>
</web>
</default>