您应该计算总页数,不要忘记添加偏移量和限制数据,还应该有模型通过限制和偏移量调用数据,因此您的 post->get per_page 值决定了下一个数据是什么。并从您的视图中加载分页。我还从我的 lang 文件中放入了第一个和最后一个值。反之亦然,有一天您可能需要更改语言。
[Codeigniter 分页][1]
totalRows,通过count listdata查找所有数据,通过limit offset offset查找所有数据,通过从per_page获取数据来决定offset在哪里获取值。
> $data ['listvalues'] = $this->some_model->listdata ($limit, $offset);
> $this->load->library ( 'pagination' ); $data ['totalRows'] =
> $this->some_model->totalRows ( ); $limit = 10; $per_page = 10; $params
> = $this->uri->uri_to_assoc (); $offset = $this->input->get ( 'per_page' ); $config = array ( 'uri_segment' => 1, 'per_page' =>
> $per_page, 'total_rows' => $data ['totalRows'], 'base_url' =>
> site_url ( 'somepage/?' ), 'page_query_string' => TRUE,
> 'full_tag_open' => '<ul>', 'full_tag_close' => '</ul>',
> 'cur_tag_open' => '<li class="active"><a>', 'cur_tag_close' =>
> '</a></li>', 'prev_tag_open' => '<li>', 'prev_tag_close' => '</li>',
> 'next_tag_open' => '<li>', 'next_tag_close' => '</li>',
> 'num_tag_open' => '<li>', 'first_link' => lang (
> 'links_pagination_first' ), 'last_link' => lang (
> 'links_pagination_last' ), 'last_tag_open' => '<li>',
> 'last_tag_close' => '</li>', 'first_tag_open' => '<li>',
> 'first_tag_close' => '</li>', 'first_link' => lang (
> 'links_pagination_first' ), 'last_link' => lang (
> 'links_pagination_last' ), 'num_links' => '10' );
> $this->pagination->initialize ( $config );
> $data ['pagination'] = $this->pagination->create_links ();