Search code examples
cakephproutescakephp-2.x

How can I manage two different routings for a single given user in CakePHP?


For example :

Router::connect(
    '/:username', 
    array('controller' => 'users', 'action' => 'profile'),
    array('pass' => array('username'))
);

If the username parameter is prefixed by @, then it will redirect to a method. If not, it will redirect to different method.

Note : I'm using version 2.8


Solution

  • This should work:

    Router::connect(
        '/@:username', 
        array('controller' => 'users', 'action' => 'action1'),
        array('pass' => array('username'))
    );
    
    Router::connect(
        '/:username', 
        array('controller' => 'users', 'action' => 'action2'),
        array('pass' => array('username'))
    );