我正在使用 CakePHP 1.3。我有一个产品模型。在数据库表中,有id
和slug
字段。
如果我有一个产品id:37
并且slug:My-Product-Title
我希望产品的 URL 是:
产品/37/我的产品标题
而不是标准:
产品/视图/37
我创建了一条如下所示的路线:
Router::connect(
'/products/:id/:slug',
array('controller' => 'products', 'action' => 'view'),
array('pass' => array('id'), 'id' => '[0-9]+')
);
现在我可以去http://server/products/37/My-Product-Title
,它把我带到正确的地方。
但是如何获得反向路由以自动构建正确的 URL $HtmlHelper->link
?
当我使用:
echo $html->link(
'Product 37',
array('controller'=>'products', 'action' => 'view', 37)
);
它仍然输出标准products/view/37
url。