简体   繁体   中英

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!

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'
));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM