views:

27

answers:

2

Hi,

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'], array('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?

Thanks,

Jonesy

+2  A: 

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]+')
);
Jordan
+3  A: 

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')
);
Till
this is brilliant but the only problem now is my tag controller is giving me and error with function index($tag){ } error is 'Missing argument 1 for TagsController::index()' when i remove the parameter from the action the error disappears
iamjonesy
to answer my question above: $tag = mysql_real_escape_string($this->params['tag']);
iamjonesy
Glad you figured it out! :)
Till