General warning — while ideally it should be supported, what you're trying to do isn't really meant to be done by a non-core Magento developer. The abstractions around routing are confusing, and possibly incomplete. It's relatively safe to introduce a new router object with a match
method, but (as you've seen) expecting it to behave in predicable ways with the system is asking Magento too much. Generally speaking, if you want a special URL in Magento, you use the rewrite system (either the rewrite models, or the configuration rewrites)
But that's not any fun.
So, the particular problem you're running into is a routername/frontName mismatch. Your router configuration is named customsearch
, but your frontName
is named lookfor
. This is a common problem when customizing system behavior, because most developers don't realize there's a difference between these two. That's because Magento core code always has them match each other. You see this this a lot in the various methods of replacing a controller action, and having the layout handles generated not match the layout handles Magento expects.
Looking at your specific problem, my guess (because it's hard to tell with the information provided) is your custom router class
`Namespace_Customsearch_Controller_Router`
in inheriting from the Mage_Core_Controller_Varien_Router_Abstract
class. If you look at the getFrontNameByRoute
method definition there
#File: app/code/core/Mage/Core/Controller/Varien/Router/Abstract.php
public function getFrontNameByRoute($routeName)
{
return $routeName;
}
You can see the method is essentially a placeholder. In the standard router
#File: app/code/core/Mage/Core/Controller/Varien/Router/Standard.php
public function getFrontNameByRoute($routeName)
{
if (isset($this->_routes[$routeName])) {
return $this->_routes[$routeName];
}
return false;
}
This method checks the configuration built up in the internal _routes
array, and returns the value it finds (which will be the frontName).
As I said, my guess is your router object inherits from the Abstract class, and doesn't have a custom getFrontNameByRoute
method. Your router object needs a similar/identical method, or needs to inherit from the standard router to have this functionality.
You will need a custom module that only changes the frontname of a module (Mage_Customer
in this case.)
Let's name the module Easylife_User
This module contains only 2 files.
app/etc/module/Easylife_User.xml
- the declaration file
<?xml version="1.0"?>
<config>
<modules>
<Easylife_User>
<codePool>local</codePool>
<active>true</active>
<depends>
<Mage_Customer /><!-- should depend on Mage_Customer so it is loaded after it -->
</depends>
</Easylife_User>
</modules>
</config>
app/code/local/Easylife/User/etc/config.xml
- the configuration file
<?xml version="1.0"?>
<config>
<modules>
<Easylife_User>
<version>1.0.0</version>
</Easylife_User>
</modules>
<frontend>
<secure_url>
<customer>/user/</customer><!-- might be needed if you have secure urls but not sure -->
</secure_url>
<routers>
<customer><!-- for the customer route... -->
<args>
<frontName>user</frontName><!-- just change the front name -->
</args>
</customer>
</routers>
</frontend>
</config>
Clear the cache and you are done.
If all your links to the customer pages are generated using ->getUrl('customer/...')
. This should work.
If you have links in your templates like this
<a href="/customer/...">Customer</a>
It won't work. But anyway, you shouldn't have links like the example above.
Best Answer
In this excellent post by Alan Storm, I found a hint to a possible solution. You should register your own router. An example can be found in Magento's CMS module.
In the CMS module's config.xml find this section:
The method
initControllerRouters()
registers a new router:...that will be iterated in app/code/core/Mage/Core/Controller/Varien/Front.php:
The match() method of the CMS-Router contains this code:
...which leads to the file Cms/controllers/PageController.php. The class inside is named
Mage_Cms_PageController
and has a methodviewAction()
that asks for the request's parameterpage_id
. From here, you can look further at the methodMage::helper('cms/page')->renderPage($this, $pageId)
.I think another big problem will be, if the configured frontName matches that of a system frontName, or the frontName defined by another module. I have no idea how this might work out.