1
votes

I have tried to modify my routes in app/config/routes.php.

I have urls like this: http://example.com/controller/action/params I would like urls like this: http://example.com/controller/params

here is my route I have built as I understand it:

Router::connect('/services/:slug', 
array('controller' => 'services', 'action' => 'view'), 
array('pass' => array('slug')));

and here is my link in my index.ctp file for services:

echo $this->Html->link(
     __($service['Service']['title'], true),
    array('controller' => 'services', 'action' => 'view', service['Service']'slug'])
); 

If it helps, here is my view function from the services controller:

    function view($slug) {
        $service = $this->Service->findBySlug($slug);

        $this->set('service', $service);
    }
1

1 Answers

0
votes

You are almost there. The view file to the action route is view.ctp(the method name) rather than index.ctp

In your link you can do:

<?php
echo $this->Html->link(
__($service['Service']['title'], true),
array('controller' => 'services', 'action' => $service['Service']['slug'])
?>

Without a method at the 'action' param because your settings will do the routing for you.