代码如下 | 复制代码 |
$this->load->library('pagination'); $id = $this->input->get('id'); /** * pagination */ $config['base_url'] = base_url().'poster_admin/works/search'; $config['per_page'] = 5; $config['num_links'] = 7; $config['uri_segment'] = '4'; $config['use_page_numbers'] = TRUE; $config['full_tag_open'] = '
$config['full_tag_close'] = ' $config['cur_tag_open'] = ' $config['cur_tag_close'] = ' $config['num_tag_open'] = ' $config['num_tag_close'] = ' $config['prev_tag_open'] = ' $config['prev_tag_close'] = ' $config['next_tag_open'] = ' $config['next_tag_close'] = ' $config['first_link'] = FALSE; $config['last_link'] = FALSE; $config['total_rows'] = $this->works_model->searchNum($id); $config['suffix'] = '?id='.$this->input->get('id'); $config['first_url'] = base_url().'poster_admin/works/search'.'?id='.$this->input->get('id'); $this->pagination->initialize($config); |
base_url相当于不变的一个基础链接。uri_segment切割url的字段,可
。分页内里也有相关介绍,告诉系统哪个字段是页码。
suffix可以设置给每个链接后面固定加上的东西,只有这样才能正常传递,first_url设定第一页的链接,否则的话id还是没办法在第一页传入的。
然后这就算设置完毕了,我们所需要做的只是用$query->number_rows()获取行号,然后使用limit和offset确定每个分页中显示的多少罢了。