cakephproutescakephp-2.0cakephp-2.3

Pass params into custom url route


I created custom url route like this:

Router::connect('/subjects.details', array(
    'plugin' => 'subjects',
    'controller' => 'subjects',
    'action' => 'details'
));

However that action/view needs a parameter.

So when I go to link like localhost/foo/subjects.details/12 it gives me missing controller error.

Missing Controller

Error: Subjects.detailsController could not be found.

Error: Create the class Subjects.detailsController below in file: app/Controller/Subjects.detailsController.php

How do I add id param for this url?


Solution

  • You have to define the param in the url and in your action as well:

      Router::connect('/subjects.details/:id', array(
            'plugin' => 'subjects',
            'controller' => 'subjects',
            'action' => 'details'
        ));