1
votes

I am trying to create a custom route like this one mysite.com/username/controller/action/params. Basically after the user is authenticated to have its username appear in the url after the domain.

I tried the examples in the book but had no luck.

This is what I tried but was no help: Router::connect('/:username/:controller/:action', array()); Router::connect('/:controller/:action', array());

Can you guys help me??

Thanks in advance,

Denis

1
Hi .. i have same problem .. did you solve this problem .. i need your help to solve my problem..Puzzled Boy
Hi, puzzled boy. Never solved this one, just gave up and started with Symfony.Denis Rendler

1 Answers

3
votes

Cake doesn't automagically know what you mean with the :username parameter of your route. There are three default parameters that need no further configuration, those are:

  1. :controller
  2. :action
  3. :plugin

All other parameters need to be specified with a matching regular expression and additionally you will need to specify an array called pass to tell Cake it should pass the parameter to your controller's action for this page. In your case, the route should probably look something like this:

Router::connect(
    '/:username/:controller/:action',
    array(), // Since you already have the controller and action in your URL there is no need for further directions here
    array(
        'pass' => array('username'), // If you want to pass the username to your action
        'username' => '[a-zA-Z0-9]+' // What regex the username should match
    ),
); 

Also see the book's page about Routing and specifically this paragraph for further reference.