gpt4 book ai didi

cakephp-2.3 - 删除最后一页的最后一条记录时cakephp分页助手显示错误

转载 作者:行者123 更新时间:2023-12-04 20:43:50 26 4
gpt4 key购买 nike

如果从最后一页删除最后一条记录,我只想将其重定向到最后一个索引。
请帮我做这件事。

<?php                       
echo $this->Paginator->prev
($this->Html->image('prev.png'), array('escape' => false),
array(), null, array('class' => 'prev'));
echo $this->Paginator->counter
('Page {:page} of {:pages}, Total Records {:count}');
echo $this->Paginator->next($this->Html->image
('next.png'), array('escape' => false),
array(), null, array('class' => 'next'));
?>

最佳答案

从 CakePHP 2.3 开始 - Out of Range page requests会抛出异常。

然而,文档说分页参数将在 $this->request->params['paging'] 中对您可用是不正确的,因为这些参数是在抛出异常之后定义的。 (这个问题已经在两个月前的 CakePHP 2.4.x 中修复了)

因此,要获得您想要的效果,您可以在 Controller 中执行以下操作:

public function index() {
try {
$paginatedData = $this->Paginator->paginate();
} catch (NotFoundException $e) {
//get current page
$page = $this->request->params['named']['page'];
if( $page > 1 ){
//redirect to previous page
$this->redirect( array( "page" => $page-1 ) );
}else{
$paginatedData = array(); //no data to paginate so use empty array()
//you will have to check for this in the view and no longer display the pagination links, since they will NOT be defined
}
}
}

关于cakephp-2.3 - 删除最后一页的最后一条记录时cakephp分页助手显示错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21421935/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com