1
我是Codeigniter分頁的新手,所以我無法正確配置它,爲什麼我需要您的幫助人員。無法在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 如果我在任何頁面點擊數我得到的空白頁,我的網址更改爲http://mypage.si/rest/api/nearbay/nearbay?
所以我的問題是。如何讓分頁工作?如何正確配置分頁,所以我將能夠通過頁面和?per_page值谷歌網址獲取結果..我的最終鏈接應該看起來像這樣http://mypage.si/rest/api/nearbay/nearbay?page=1&per_page=20
如果您需要任何其他信息,請讓我知道,我會提供... 謝謝!
這不是我的情況,但我從你的代碼中得到了一些提示,所以我會接受答案!謝謝! –