作者:俏君woo_267 | 来源:互联网 | 2023-02-13 09:50
这里我们以get与分页的结合为例,因为这点当时我纠结了很久,当然是在M-SHOW时候纠结完的,这次拿来主义了一次,记录一下<?php$this->load->l
这里我们以get与分页的结合为例,因为这点当时我纠结了很久,当然是在M-SHOW时候纠结完的,这次拿来主义了一次,记录一下
load->library(&#39;pagination&#39;);
$id = $this->input->get(&#39;id&#39;);
/**
* pagination
*/
$config[&#39;base_url&#39;] = base_url().&#39;poster_admin/works/search&#39;;
$config[&#39;per_page&#39;] = 5;
$config[&#39;num_links&#39;] = 7;
$config[&#39;uri_segment&#39;] = &#39;4&#39;;
$config[&#39;use_page_numbers&#39;] = TRUE;
$config[&#39;full_tag_open&#39;] = &#39;
&#39;;
$config[&#39;full_tag_close&#39;] = &#39;
&#39;;
$config[&#39;cur_tag_open&#39;] = &#39;
&#39;;
$config[&#39;cur_tag_close&#39;] = &#39;&#39;;
$config[&#39;num_tag_open&#39;] = &#39;
&#39;;
$config[&#39;num_tag_close&#39;] = &#39;&#39;;
$config[&#39;prev_tag_open&#39;] = &#39;
&#39;;
$config[&#39;prev_tag_close&#39;] = &#39;&#39;;
$config[&#39;next_tag_open&#39;] = &#39;
&#39;;
$config[&#39;next_tag_close&#39;] = &#39;&#39;;
$config[&#39;first_link&#39;] = FALSE;
$config[&#39;last_link&#39;] = FALSE;
$config[&#39;total_rows&#39;] = $this->works_model->searchNum($id);
$config[&#39;suffix&#39;] = &#39;?id=&#39;.$this->input->get(&#39;id&#39;);
$config[&#39;first_url&#39;] = base_url().&#39;poster_admin/works/search&#39;.&#39;?id=&#39;.$this->input->get(&#39;id&#39;);
$this->pagination->initialize($config);
base_url相当于不变的一个基础链接。uri_segment切割url的字段,可
。分页内里也有相关介绍,告诉系统哪个字段是页码。
suffix可以设置给每个链接后面固定加上的东西,只有这样才能正常传递,first_url设定第一页的链接,否则的话id还是没办法在第一页传入的。
然后这就算设置完毕了,我们所需要做的只是用$query->number_rows()获取行号,然后使用limit和offset确定每个分页中显示的多少罢了。