CakePHP: How to route page sorting options?

So, I am trying to place pages on my index page using pagarin and custom routes. All this is through an index action, but an index action can show items sorted by newest, votes, active or views. Right now the url is as follows:

items/index/sort:created/direction:desc

And if you are not on the first page, it looks like this:

items/index/sort:created/direction:desc/page:2

I would like to use a router so that it looks like this:

newest/

I can go this far along this route:

  Router::connect(
    '/newest/*',
    array('controller'=>'items', 'action'=>'index', 'sort'=>'created', 'direction'=>'desc')
);

However, pager links do not follow the route. As soon as you click on the next page, you will return to:

items/index/sort:created/direction:desc/page:2

, , , ? , , .

+3
2

( ). - paginator?

:

Router::connect('/newest/*',array('controller'=>'tests', 'action'=>'index', 'sort'=>'age', 'direction'=>'desc'));
Router::connect('/oldest/*',array('controller'=>'tests', 'action'=>'index', 'sort'=>'age', 'direction'=>'asc'));

URL, , :

http://localhost/cakephp/1.3.0/newest/page:1
http://localhost/cakephp/1.3.0/newest/page:2
http://localhost/cakephp/1.3.0/newest/page:3

:

http://localhost/cakephp/1.3.0/oldest/page:1
http://localhost/cakephp/1.3.0/oldest/page:2
http://localhost/cakephp/1.3.0/oldest/page:3

(, , 1,2,3 , ).

+3

, . - ,

$this->params = $this->passedArgs();

, http://book.cakephp.org/view/46/Routes-Configuration

HTML-, , URL- . :)

, , . .

function newest(){

}
function votes(){

}
function active(){

}

//etc
0

Source: https://habr.com/ru/post/1773189/


All Articles