I'm doing QA on this new app I've created using CI. With pagination implemented, what's the typical way of dealing with invalid page numbers? Nothing stops me from manually 开发者_运维问答changing the offset in the URL manually. So if the max is 20, if I modify to 100 what should happen? I'm brainstorming on ways to check if the offset is valid and if it isn't redirect somewhere or display an error message (not sure if I care to do so).
You could do a check on the numbers of results returned and return a 404.
if ($this->page->get_pages(20, 100) {
$this->load->view('our_view');
} else {
show_404();
}
If anyone comes across this later, here's how I tackled the issue.
$max_offset = (ceil($config['total_rows'] / $config['per_page']) - 1) * $config['per_page'];
if (($this->start > $max_offset) && ($max_offset >= 0)) {
redirect("/report/filter");
} else {
$data['records'] = $this->report_model->filterItem($records, false, $config['per_page'], $this->start);
$this->load->view('report_view', $data);
}
精彩评论