PinoyStackOverflower
PinoyStackOverflower

Reputation: 5302

CakePHP remove the index action from the URL

How do I remove the index action from the URL?

Here is my code in routes.php

Router::connect('/jobs/:slug',array('controller'=>'jobs','action'=>'index'));

So basically, i have this url:

http://example.com/jobs/index/pharmacist

but I want to change that one into

http://example.com/jobs/pharmacist

Would this configuration be purely in routes.php or I should need to edit my .htaccess, I honestly absolutely don't have any idea.

Your help will be greatly appreciated. Thanks!

Upvotes: 4

Views: 896

Answers (1)

Anil kumar
Anil kumar

Reputation: 4177

According to Docs

By using the 3rd argument of Router::connect() you can define which route elements should also be made available as passed arguments:

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

and in your view you can generate link using

echo $this->Html->link('link', array(
    'controller' => 'jobs',
    'action' => 'index',
    'slug' => 'your_slug'
));

Upvotes: 1

Related Questions