简体   繁体   中英

Changing the routes for named parameters in CakePHP

I have the following two routes which make the url /posts/recent show page 1 of the recent filter on index method of my posts controller and also allow paging like: /posts/recent/page:2 by using the * on the next route. As you can see I call page 1 on the first route so that I don't get duplicate urls for page 1.

Router::connect('/posts/recent', array('controller'=>'posts','action'=>'index','filter'=>'recent', 'page' => 1), array('pass'=>array('filter')));


Router::connect('/posts/recent/*', array(
  'controller' => 'posts', 'action' => 'index', 'filter'=>'recent'), array(
    'named' =>array('page' => '[\d]+'),
     'pass'=>array('filter')
  )
);

However I would like to make it so that named params do this instead:

/posts/recent/page/2 but how do I do it?

I've looked around the docs but don't seem to see anything about doing this...

Also is it possible to turn off named parameters in favour of query strings?

I'm using CakePHP 2.1 if it matters.

Perhaps with Router::connectNamed()?

http://book.cakephp.org/2.0/en/development/routing.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM