开发者

CakePHP: changing link to 'tags/index/php' to just 'tags/php'

开发者 https://www.devze.com 2023-01-20 16:55 出处:网络
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.

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]+')
);
0

精彩评论

暂无评论...
验证码 换一张
取 消