-
Notifications
You must be signed in to change notification settings - Fork 6
URL Routing
pwhittlesea edited this page Jun 20, 2012
·
2 revisions
Now this project has something of a special way for routing certain URLs
If, for example, we take a project with an id of 10 and a name of github. Traditionally the project would be viewable at:
http://example.com/projects/view/10
In addition to this, the project is also available at:
http://example.com/project/github
Cleaner right? And in fact, the first will automagically redirect to the second for users (not admins).
So how do we use CakePHPs lovely reverse routing to generate the second style URL when using the default Html helper?
Well instead of this:
$this->Html->link(
'No Magic Here',
array('controller' => 'projects',
'action' => 'view',
$id,
)
);
You do this:
$this->Html->link(
'Oodles Of Magic Here',
array('action' => 'view',
'project' => $name,
)
);
So by specifying a project section of the URL, CakePHP goes away and generates the cleaner style URL. Nice huh?