CakePHP removes index action from url

How to remove an index action from a 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 it to

http://example.com/jobs/pharmacist

Will this configuration be purely in routes.phpor will I need to edit mine .htaccess, to be honest, I absolutely do not know.

Your help will be greatly appreciated. Thank!

+4
source share
1 answer

According to the docs

Using the third argument Router::connect(), you can determine which route elements should also be available as passed arguments:

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

and, in your opinion, you can create a link using

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

Source: https://habr.com/ru/post/1548005/


All Articles