我有一个名为TagsController的控制器,它从索引操作中的url获取标记名,以获得具有该标记的项目列表。
<?php
foreach($tags as $tag){
echo "<span class='homepagetags'>".$html->link($tag['t']['tag'], array('controller' => 'tags', $tag['t']['tag'])) . "</span> x " . $tag[0]['NumOccurrances'] . "<br><br>";
}
?>这个链接将我带到'tags/index/php‘,而我真的希望它是'tags/php’。
这是路由解决方案吗?
发布于 2010-10-22 08:15:05
具体地说,您需要:
// routes.php
Router::connect(
'/tags/:tag',
array('controller' => 'tags', 'action' => 'index')
);然后创建一个链接:
echo $html->link(
'PHP Tag',
array('controller' => 'tags', 'action' => 'index', 'tag' => 'php')
);发布于 2010-10-22 07:08:35
是的,有一个路由解决方案。它在食谱中的Defining Routes部分进行了大约一半的解释。示例如下:
Router::connect(
'/:controller/:id',
array('action' => 'view'),
array('id' => '[0-9]+')
);https://stackoverflow.com/questions/3992691
复制相似问题