In my application, I have a number of controllers with the same prefix. For the sake of example, let's say they are:
my_posts
my_users
my_letters
The URLs generated for these are obviously:
/my_posts/view/1
/my_users/add
/my_letters/whatever
I'd like to set up some custom routing so that I can use the URLs like this:
/my/posts/view/1
/my/users/add
/my/letters/whatever
So basically, if the URL starts with /my/
then the controller to pass to should be my_{whatever_comes_next}
.
I've been looking at the documentation, but still can't figure it out.
Router::connect(
'/my/posts/:action/*',
array(
'controller'=>'my_posts',
'action'=>'index'
)
);
Router::connect(
'/my/users/:action/*',
array(
'controller'=>'my_users',
'action'=>'index'
)
);
[..]
agreed, that that is not quite comfortable, but it should work..
Not sure that is possible, but why not use an intermediate router?
Router::connect (
'/my/*',
array (
'controller' => 'my_router',
'action' => 'route',
)
);
class MyRouterController extends AppController {
...
function route ()
{
$args = func_get_args ();
$controller = array_shift ($args);
$this->requestAction (
'my_'.$controller.'/'.implode('/', $args),
array ('return' => true)
);
}
}