Page 2 of 2
1 · 2

Saikat :: 18.08.2009 04:02:57
Hi,

After reading your article i copied the router code to routes.php.
Actual url is
http://lv.lamparch.com/index/category/Allahabad/Real-Estate-Property-Flat-Mates-Room-Mates/c123

where controller is : index and action is: category

but whenever i try the url below is get an error .
http://lv.lamparch.com/Allahabad/Real-Estate-Property-Flat-Mates-Room-Mates/c123
lecterror :: 18.08.2009 05:22:12
Hello Saikat,

You "short" URL is not matched by the regex part [a-zA-Z\-_]+/? which will match only a portion of it. You should probably create a different (and probably more complex) regex(es) which will fit your site better. Something in the line of connecting a route '/:a/:b/:c' with regexes for all three items:

'a' => '(?!('.$controllers.')\W+)[a-zA-Z0-9\-_]+'
'b' => '[a-zA-Z0-9\-_]+'
'c' => '[a-zA-Z0-9\-_]+'
Elte :: 26.12.2009 15:26:05
Very nice solution! But it doesn't account for plugins. Since it's only about the first argument I think it would suffice to replace this:

$controllers = Configure::listObjects('controller');

with this:

$controllers = am(Configure::listObjects('controller'), Configure::listObjects('plugin'));

Also, your regex seems to match index actions without a trailing slash on existing controllers, say yourwebsite.com/somecontroller, as opposed to yourwebsite.com/comecontroller/ which does route to the correct controller (using cake 1.2.5). I'm still looking into that though..
Elte :: 26.12.2009 16:27:52
Update (sorry for the double post): I think you force the last slash with your regex. I now use this alternative which also includes end of line as part of the negative lookahead:

(?!('.$controllers.')((\W+)|$))[a-zA-Z\-_]+/?$

Seems to work nicely thusfar :).