Для разбиения на страницы(pagination) в CakePHP используется метод Router::url который устнавливает структуру ссылок на все страницы. Вы возможно заметили, что теперь он устраняет все остальные параметры из URL. Этого можно избежать, сделав некоторые изменения.
Если вы находитесь на странице, у которой структура адреса примерно такая:
/cool/page_with_stuff/like_this/and_this
Вы, наверное, заметили, что ссылки на страницы превратятся в:
/cool/page_with_stuff/page:2
Это потому, что Cake использует метод Router::url() внутри помощника paginator для создания этих ссылок.
Router::url()
вернет следующее:
/cool/page_with_stuff/like_this/and_this
но
Router::url(array('page' => 2'))
вернет следующее:
/cool/page_with_stuff/page:2
Cake already has a built in quick fix for this though. Paginator has an options function that you can use to set various things about your pagination. So simply writing:
$paginator->options(array('url' => $this->params['pass']));
Before any pagination functions are called will fix the problem. That's spelled out in the documentation already as well, so it's nothing new.
One particularly handy thing about Cake is it's helper callbacks though. So if you'd like to resolve this in all of your pages site wide with a single call you've only got to drop this code:
<?php
var $helpers = array('Paginator');
function beforeRender() {
//Set full pagination path accross all controllers
$this->Paginator->options(array('url' => $this->params['pass']));
}
?>
into one of your include one of your custom helpers (that's included on every page). My first instinct was to try this in the AppHelper, however, that triggered an error for some reason.
Anyway, I ran into this in an application that had been in development for a while and I was looking for a way to fix it across the board quickly. Hopefully somebody else will find this useful too.
Если вы находитесь на странице, у которой структура адреса примерно такая:
Вы, наверное, заметили, что ссылки на страницы превратятся в:
вернет следующее:
но
вернет следующее:
Cake already has a built in quick fix for this though. Paginator has an options function that you can use to set various things about your pagination. So simply writing:
Before any pagination functions are called will fix the problem. That's spelled out in the documentation already as well, so it's nothing new.
One particularly handy thing about Cake is it's helper callbacks though. So if you'd like to resolve this in all of your pages site wide with a single call you've only got to drop this code:
var $helpers = array('Paginator');
function beforeRender() {
//Set full pagination path accross all controllers
$this->Paginator->options(array('url' => $this->params['pass']));
}
?>
into one of your include one of your custom helpers (that's included on every page). My first instinct was to try this in the AppHelper, however, that triggered an error for some reason.
Anyway, I ran into this in an application that had been in development for a while and I was looking for a way to fix it across the board quickly. Hopefully somebody else will find this useful too.


Коментарии:
Пока нетуДобавить коментарий