[英]Codeigniter pagination id at the last segment of url
嗨,我在其他網站上有工作分頁功能,但是在這里
public function category($id=null)
{
$config = array();
$config["base_url"] = base_url() . "view/category/".$id;
$config["total_rows"] = $this->viewmodel->record_count_category_post($data['category']);
$config["per_page"] = 6;
$config['num_links'] = 10;
$this->pagination->initialize($config);
$page = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0;
$config['display_pages'] = FALSE;
$data["links"] = $this->pagination->create_links();
}
我不知道為什么分頁不起作用。 如果網址的最后一段包含數字(id),我如何使分頁工作?
更改您的$page = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0;
$page = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0;
至:
if($this->uri->segment(4))
{
$config["per_page"] = (($this->uri->segment(4)) * 6) - 6;
}
else
{
$config["per_page"] = 0;
}
像下面的示例:
public function category($id=null)
{
$config = array();
$config["base_url"] = base_url() . "view/category/".$id;
$config["total_rows"] = $this->viewmodel->record_count_category_post($data['category']);
$config["per_page"] = 6;
$config['num_links'] = 10;
$this->pagination->initialize($config);
if($this->uri->segment(4))
{
$config["per_page"] = (($this->uri->segment(4)) * 6) - 6;
}
else
{
$config["per_page"] = 0;
}
$config['display_pages'] = FALSE;
$data["links"] = $this->pagination->create_links();
}
將public function category($id=null)
更改為
public function category($id=0)
因為NULL
不會返回任何段...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.