cakephpcakephp-routingcakephp-3.x

CakePHP 3 Routing: How to route controller basis


I am using cakephp 3. I want to hide frontends controller in url.

My Routes config:

Router::connect('/:action', array('controller' => 'frontends'));

And I want to refer all function to bloggers controller when url start as www.example.com/bloggers

Router::connect('/bloggers/:action', array('controller' => 'bloggers'));

But www.example.com/bloggers also refers to frontends Controller's index function. It should refer to bloggers Controller's index function. Any help?


Solution

  • Just change the order of your routing

    First write this

    Router::connect('/bloggers/:action', array('controller' => 'bloggers'));
    

    and then this one

    Router::connect('/:action', array('controller' => 'frontends'));