Reputation: 54949
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*
I 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.
Upvotes: 0
Views: 125
Reputation: 54949
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';
}
?>
Upvotes: 0
Reputation: 3250
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'];
Upvotes: 1