我是codeigniter分页的新手。我试图按数组值配置per_page。这是我试过的例子:
//dynamic limit
$limit = array(10, 20, 30);
if (!is_null($offset)) {
$offset = $this->uri->segment(2);
}
$config['uri_segment'] = 2;
$config['base_url'] = site_url('product');
$config['total_rows'] = $this->mod_product->count_item();
$config['per_page'] = $limit;
$config['num_links'] = 10;
$this->pagination->initialize($config);
$data['links'] = $this->pagination->create_links();
$data['items'] = $this->mod_product->get_product($limit, $offset);
$this->load->view("product", $data);
答案 0 :(得分:1)
请先包含图书馆。
public function __construct() {
parent:: __construct();
$this->load->helper("url");
$this->load->model("Countries");
$this->load->library("pagination");
}
public function example1() {
$config = array();
$config["base_url"] = base_url() . "welcome/example1";
$config["total_rows"] = $this->Countries->record_count();
$config["per_page"] = 20;
$config["uri_segment"] = 3;
$this->pagination->initialize($config);
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$data["results"] = $this->Countries->
fetch_countries($config["per_page"], $page);
$data["links"] = $this->pagination->create_links();
$this->load->view("example1", $data);
}