Cakephp 超出范围的页面请求
我是cakephp的乞丐,我的版本是2.4.3 在文档中,我找到了下面的示例代码Cakephp 超出范围的页面请求,cakephp,paginator,cakephp-2.4,Cakephp,Paginator,Cakephp 2.4,我是cakephp的乞丐,我的版本是2.4.3 在文档中,我找到了下面的示例代码 public function index() { try { $this->Paginator->paginate(); } catch (NotFoundException $e) { //Do something here like redirecting to first or last page. //$this->requ
public function index() {
try {
$this->Paginator->paginate();
} catch (NotFoundException $e) {
//Do something here like redirecting to first or last page.
//$this->request->params['paging'] will give you required info.
}
}
我的问题:
1.如何重定向到最后一页,有没有办法获得总页数
2.我试图用debug()输出$this->request->params['paging'],但没有显示任何内容,只是一个空值,我做错了什么吗
请帮助我,认为
分页数据不可用可能是一个bug,也可能是文档错误-我认为是前者,因为当分页器组件已经这样做时,再次计数记录会有点多余
查看责任代码:
显示在params
数组中设置paging
键之前引发异常。因此,在修复此问题之前,您必须修改核心,或者自己重新计算,类似这样的事情(可能需要一些调整):
在CakePHP 3.4上,我有以下解决方案:
$page = (!empty($this->request->query['pagina']) ? $this->request->query['pagina'] : 1);
$this->paginate = ['page' => $page, 'limit' => '10'];
try {
$products = $this->paginate($products);
} catch (NotFoundException $e) {
$this->paginate = ['page' => $page-1, 'limit' => '10'];
$products = $this->paginate($products);
}
知道了!非常感谢!!
$page = (!empty($this->request->query['pagina']) ? $this->request->query['pagina'] : 1);
$this->paginate = ['page' => $page, 'limit' => '10'];
try {
$products = $this->paginate($products);
} catch (NotFoundException $e) {
$this->paginate = ['page' => $page-1, 'limit' => '10'];
$products = $this->paginate($products);
}