i am new to cakephp,I am unable to find a proper way to get the count of records in a page from a list. I have a list of batches in my page with pagination limit of 20 records per page.I want to know how to check if the records in the current page is empty and then redirect to page 1 if there are no more records in the current page after deleting a record.
When Paginator has no results, it throws the NotFoundException
. You need to use try/catch
in your Controller and proceed with the required next steps:
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
));
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.