I am using CakePHP 1.3. I have a Product model. on the DB table among others there are id
and slug
fields.
If I have a product that is id:37
and slug:My-Product-Title
I want the URL for the product to be:
products/37/My-Product-Title
Instead of the standard:
products/view/37
I created a route that looks like this:
Router::connect(
'/products/:id/:slug',
array('controller' => 'products', 'action' => 'view'),
array('pass' => array('id'), 'id' => '[0-9]+')
);
Now I can go to http://server/products/37/My-Product-Title
and it takes me to the right place.
But How do I get reverse routing to automatically build the correct URL in $HtmlHelper->link
?
When I use:
echo $html->link(
'Product 37',
array('controller'=>'products', 'action' => 'view', 37)
);
It still outputs the standard products/view/37
url.