CakePHP从URL中删除索引操作


CakePHP remove the index action from the URL

如何从URL中删除索引操作?

这是我的代码在routes.php

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

基本上,我有这个url:

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

但是我想把它改成

http://example.com/jobs/pharmacist

这个配置是纯粹在routes.php中还是我应该需要编辑我的.htaccess,我真的完全不知道。

非常感谢你的帮助。谢谢!

根据Docs

通过使用Router::connect()的第三个参数,你可以定义哪些路由元素也应该作为传递的参数可用:

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

,在你的视图中,你可以使用

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