I’m trying to configure my custom routes in cakephp such that the url
/objects/id/action => ObjectsController.action() with params[‘id’]=id
(This is so that I don’t have to have urls like /objects/action/id which logically make less sense to me than objects/id/action).
I still want /objects/action to trigger ObjectsController.action() (e.g. for add, index, search).
My routes config looks like this:
Router::connect('/:controller/:id',
array('action'=>'view'),
array(
':id' => '^[0-9]+$'
)
);
Router::connect('/:controller/:id/:action/*',
array('action'=>'view'),
array(
':id' => '^[0-9]+$',
':action' => '[A-Za-z0-9_\-]*'
)
);
This works with (for example):
- /objects/54
- /objects/54/edit
- /objects/add
But not with
- /objects/index/page:2
For which it gives me the error that I need to define the action “page:2” in ObjectsController… Surely it should work, because :id should only match digits, no?
Try to remove “:” from second param:
Also see ‘pass’ option.
@see google on “cakephp routes”: