[英]Redirect page to first page when there is no more records in the nth page after deletion in cakephp 2
我是 cakephp 的新手,我无法找到正确的方法来从列表中获取页面中的记录数。 我的页面中有一个批次列表,每页分页限制为 20 条记录。我想知道如何检查当前页面中的记录是否为空,如果当前页面中没有更多记录,则重定向到第 1 页删除记录后。
当 Paginator 没有结果时,它会抛出NotFoundException
。 您需要在 Controller 中使用try/catch
并继续执行所需的后续步骤:
try {
$this->set('results', $this->Paginator->paginate($this->modelClass));
} catch (NotFoundException $e) {
return $this->redirect(array(
'action' => 'index',
'?' => $this->request->query,
'page' => 1
));
} catch (Exception $e) {
return $this->redirect(array(
'action' => 'index',
'?' => $this->request->query,
'page' => 1
));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.