I have a controller called TagsController that takes the tag name from the url in the index action to get a list of projects with that tag.
<?php
foreach($tags as $tag){
echo "<span class='homepagetags'>".$html->link($tag['t']['tag'], a开发者_StackOverflowrray('controller' => 'tags', $tag['t']['tag'])) . "</span> x " . $tag[0]['NumOccurrances'] . "<br><br>";
}
?>
the link takes me to 'tags/index/php' when I really just want it to be 'tags/php'
Is this a routing solution?
Specifically, you need:
// routes.php
Router::connect(
'/tags/:tag',
array('controller' => 'tags', 'action' => 'index')
);
Then to create a link:
echo $html->link(
'PHP Tag',
array('controller' => 'tags', 'action' => 'index', 'tag' => 'php')
);
Yes, there is a routing solution. It is explained about half way down the Defining Routes section in the Cookbook. The example is:
Router::connect(
'/:controller/:id',
array('action' => 'view'),
array('id' => '[0-9]+')
);
精彩评论