As Jonathan mentioned, to do that with old routes you will need to hardcode 
a list of your controllers. Then anything what is not a controller is a 
username. But this is not the best way to do it. I like better the way the 
new router works, that is using predefined defaults.

So what you could do is having a number of user function in a user 
controller, eg. /user/create, /user/update, /user/delete and set one of this 
functions as your application default, e.g. /user/show. Now, any request to 
/name for name not in controllers would be mapped to /user/show/name. Unless 
Jonathan will correct me here, as rather "name" would be used as function of 
the default controller, i.e. /user/name. But let's assume this will work 
fine, then for other functions you just use the user name as one of the 
arguments e.g. /settings/appearance.xml/bruno/1/?color=blue. An alternative 
option would be to use different subdomain for each user 
http://bruno.twitter.com/settings/appearance.json but I don't think this is 
supported in any way by new routes.

A more complete solution to tackle this (and other examples I mentioned in 
the beta routes thread) could be something similar to $label replacement 
used in old routes. With this implemented, an example usage for Bruno's case 
would look like this:
"/$user/$controller/$function/$args/$vars" -> 
"/$controller/$function/$args/$vars&client=$user" or
"/$user/$controller/$function/$args" -> 
"/$controller/$function/$user/$args".

How this should work? Each of the labels would simply match a regex of (.+) 
or maybe more limited ([\w.-]+) with exception of the last label (here $vars 
in example 1 and $args in example 2) which could contain also special 
characters [/+...@?=&;:,*!()']. Or maybe even to simplify things, everything 
between two "/" characters would be assigned to a label. Then the labels 
would be used to reorder parts of urls. After reorder is done the new router 
would deal with the string as if it was the original url. I assume all this 
is app-specific and domain and app parts are stripped before.

Notice that this would be quite general and you could do with it things 
like:
"/author/$name"  ->  "/books/author?name=$name"
or even url shortening like:
"/short-name"  ->  "/controller/func/arg1/arg2/arg3/arg4"

Alternative option would be having named routes like 
Routes<http://routes.groovie.org/manual.html>does and instead of arbitrary 
label used specific ones for controller and 
function and treat the rest as query arguments of it, e.g:
"/{user}/new/{controller}/{function}" will give "/c/f/user=smith" for 
"/smith/new/c/f"
but I guess this is a bit too complex and not clearly better than the other 
method (although I like {label} notation better than $label).

OK, so I leave you with these ideas. Maybe we could find a nice way of 
making the new routes a bit more flexible by discussing this further.

Reply via email to