【发布时间】:2017-09-14 18:36:43
【问题描述】:
我是 Codeigniter 分页的新手,所以我无法正确配置它,这就是为什么我需要你们的帮助。
这是我目前的代码
public function nearbay_get($idNearBay = null)
{
$config['base_url'] = 'http://mypage.si/rest/api/nearbay/nearbay';
$config['total_rows'] = $this->Near_bays->count();
$config["per_page"] = 5;
$config['first_link'] = 'First';
$config['last_link'] = 'Last';
$config['suffix'] = '?'.http_build_query($_GET, '', "&");
$config['use_page_numbers'] = TRUE;
$config['enable_query_strings'] = 'page=';
$choice = $config["total_rows"] / $config["per_page"];
$config["num_links"] = round($choice);
$this->pagination->initialize($config);
$page = ($this->uri->segment(6))? $this->uri->segment(6) : 0;
$results = $this->Near_bays->get(null, [null, null], [null, null], '', $config["per_page"], $page);
foreach($results as $data) {
echo $data->id_near_bay . " ------- " . $data->name . "<br>";
}
echo $this->pagination->create_links();
}
如果我访问http://mypage.si/rest/api/nearbay/nearbay,这就是结果 如果我点击任何页码,我会得到空白页,我的 url 会更改为http://mypage.si/rest/api/nearbay/nearbay?
所以我的问题是。如何让分页工作?如何正确配置分页,以便我能够通过 ?page 和 ?per_page 值通过 url 获取结果。我的最终链接应该如下所示http://mypage.si/rest/api/nearbay/nearbay?page=1&per_page=20
如果您需要任何其他信息,请告诉我,我会提供...谢谢!
【问题讨论】:
标签: php rest codeigniter pagination