我的分页代码如下。我无法从url中获取值,而且分页也不起作用:
public function categories_product(){
$categoryid = $_GET['catId'];
$categoryname = $_GET['cname'];
$data = array();
$config["base_url"] = base_url() . "pages/categories_product?catId=".$categoryid."&cname=".$categoryname ;
}
$this->load->library('pagination');
$config['per_page']= 10;
$config['uri_segment'] = 4;
$config['base_url'] = 'URL where you want to run pagination';
计数的记录总数
$this->data['totalcount'] = 'total records';
初始化库
$this->pagination->initialize($config);
$this->data['paginglinks'] = $this->pagination->create_links();
$this->data['per_page'] = $this->uri->segment(4);
$this->data['page'] = $offset;
$this->data['per_page_display'] = $config['per_page'];
也许可以这样做,而不是使用查询字符串(我认为您需要在Codeigner配置文件中启用查询字符串,但我不确定,因为我已经很久没有使用它了)
$config["base_url"] = base_url() . "pages/categories_product/".$categoryid."/".$categoryname;
// Telling pagination that pagination parameters will go from 5th segment
$config['uri_segment'] = 5;
$this->pagination->initialize($config);
echo $this->pagination->create_links();
此外,这对SEO更友好,也更符合Codeigner风格。
在此处查找自定义分页http://www.codeigniter.com/user_guide/libraries/pagination.html