If you are viewing some post / post on a Cake site, then most likely the address looks like this:
/ posts / view / 5 , where posts is the model, and 5 is the id number of the post.
To generate such a link you need to register something like:
$html->link('CakePHP Tips', array('controller' => 'Post','action' => 'view',5));
Naturally you will not write id manually, most likely it will be something like:
$html->link($post['Post']['title'], array('controller' => 'Post','action' => 'view',$post['Post']['id']));
And now the most interesting:
You can write an additional parameter and it will be redirected to the same place.
That is
/ posts / views / 5 / Cakephp-tips , leads in the same place as
/ posts / views / 5Everything! We don't need to keep Slug anywhere else. Enough to register it in the link
$html->link($post['Post']['title'], array('controller' => 'Post', 'action'=>'view', $post['Post']['id'], Inflector::slug($post['Post']['title'], '-')));
This will give us something like: / posts / view / 5 / cakephp_tips
')
Cross post from
my blog