Abdus Sattar Bhuiyan
Abdus Sattar Bhuiyan

Reputation: 3074

Routing in CakePHP 2.6.9

I am using CakePHP 2.6.9.

I want to do following:

  1. www.example.com/detail/10 should refer to controller => frontends and action => detail
  2. www.example.com/admins/login should refer to controller => admins and action => login

I edited routes.php as follows:

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

But when I try www.example.com/admins/login it shows the following error:

The action admins is not defined in controller FrontendsController

It proves that www.example.com/admins/login refers to

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

Routing. I want

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

will be only for controller => frontends and action=>detail, rest of url will work as default. Any idea?

Upvotes: 0

Views: 82

Answers (1)

user3082321
user3082321

Reputation: 654

this will do want you want.

Router::connect('/detail/*', array('controller' => 'Frontends', 'action' =>'detail'));

Mostly cakephp urls are like /controller/action/id. Your template of the route /:action/* tells that you are not using controller names in urls instead you are using only action names like /detail/id and /admins/id, and all actions are in Frontends controller. You can see from the error message that it tried to find admins action in Frontends conntroller.

Upvotes: 3

Related Questions