Cakephp has been supporting admin routes for a long time. It’s also possible to use custom prefixes next to your admin routes for extra flexibility. However you will probably face some problems when you start using prefix routes. I’ll show you how to handle some of them.
First of all let’s create our prefix route
Router::connect('/manager/:controller/:action/*', array('prefix' => 'manager', 'manager' => true));
Links
Creating links to your prefixed actions is easy
echo $html->link('Edit user', array('controller' => 'users', 'action' => 'edit', 'manager' => true, 1));
This will create a link to : ‘/manager/users/edit/1′
Pagination
When using pagination in your prefixed actions, you’ll notice the paginator helper doesn’t output the correct url’s by default. Here’s how to fix it:
$paginator->options(array('url' => array('manager' => true)));
Forms
The form helper doesn’t detect the prefix automatically also.. here’s how to solve it
echo $form->create('User', array('url' => $html->url(array('pb' => true, $this->data['User']['id']))));
Unfortunately the Router class doesn’t detect the prefixes automatically, like it does with admin routes. Which results in a lot of extra code and work when you decide to use prefixes. Hopefully this will be changed in later releases.
Thank you so much.
I found this article after 2hour googling by ‘cakephp paginator prefix’
Same deal as with chez, there doesn’t seem to be any relevant documentation on using custom prefix routing with pagination in CakePHP. Thanks. By the way, the third piece of code under “Pagination” is missing the third closing parenthesis.
[...] CakePHP router and custom prefixes Found this cool info here [...]
*Bookmarked*… thanks so much, I’ve been wrestling with custom prefixes for a week now!
$paginator->options(array('url' => array('manager' => true));Should be
$paginator->options(array('url' => array('manager' => true)));THanks for the great code! couldn’t find it anywhere else.
Thanks for noting Matt!