views:

25

answers:

2

I have a users module and few actions like wall, dishes, restaurants, photos.

i wanna set up a routing like something like this

site.com/users/{userId or Username}/wall => should route to wall() action

site.com/users/{userId or Username}/dishes => should route to dishes() action

site.com/users/{userId or Username}/restaurants => should route to restaurants() action

site.com/users/{userId or Username}/photos => should route to photos() action

am not sure how to keep the url intact in the address bar but load the actions.. where user id or username is passed onto the action.

+1  A: 

Try:

Router::connect(
    '/users/:id/:action',
    array(
      'controller' => 'users'
      'id' => '[0-9]+') # or [a-zA-Z0-9] for username
);

Also in those action (wall, dishes...) you need to add:

$id = $this->params['id'];
PawelMysior
`'pass' => array('id')` http://book.cakephp.org/view/543/Passing-parameters-to-action
deizel
A: 

http://bakery.cakephp.org/articles/view/cakephp-s-routing-explained

<?php
Router::connect(
    '/writings/:username/:action/:id/*', 
    array(
        'controller' => 'articles'
    ),
    array(
        'pass' => array(
            'id',
            'username'
        )
    )
);
?> 

Having this route makes CakePHP call your action like $Controller->show(69, 'phally') and then your action should look like:

<?php
public function show($id = null, $username = null) {
    // $id == 69;
    // $username == 'phally';
}
?> 
Harsha M V