CI分页,一个奇怪的问题
本帖最后由 不科学 于 2015-6-24 15:44 编辑public function index($tag = "2009")
{
$total = count($this->Blog_model->count_tag($tag));//获取当前分类的文章数量
$config['base_url']= site_url().'/tag/index/'.$tag;
$config['total_rows']= $total ;
$config['per_page']= 20;
$this->pagination->initialize($config);
$data['items'] = $this->Blog_model->tag_items($tag, $config['per_page'], $this->uri->segment(4));//根据$limit、$offset取出文章
if (empty($data['items']))
{
show_404();
}
$data['cat_items'] = $this->Blog_model->category();
$data['page_links'] = $this->pagination->create_links();
$this->load->view('templates/header',$data);
$this->load->view('tag',$data);
}
这是tag类的一个index方法
链接是这样:ci/index.php/tag/index/2010
理论上该页面应该是tag=2010时的第一页,实际显示是这样:
http://codeigniter.org.cn/forums/data/attachment/album/201506/23/182345rdyhlfyjtx5mhpap.png
当我把链接手动改成ci/index.php/tag/index/2010/00时,就会正常显示在第1页。
几乎是相同的代码,只是具体参数不同,我写的category类就完全没问题。
有知道的人吗? 我刚重现了问题, 只要是输入的参数 超过了10,分页就会出现问题。
比如ci/index.php/tag/index/9 , 就不会出现问题。
比如ci/index.php/tag/index/10,就会出现问题。
但是如果手动改成ci/index.php/tag/index/10/00,就正常了。 http://stackoverflow.com/questions/22056895/ci-class-pagination-links-trouble 加上了$config['uri_segment'] = 2;就可以正常了。
但是翻页之后,当前页一直显示 1 。 醉了 解决了。
代码里面加上
$config['uri_segment'] = 4;//具体我没搞明白,可能是告诉程序链接里面哪一个部分才是分页。比如我这个链接就是分成了是个部分,参数15后面的才是分页的参数。
index.php/category/index/15 我被分页的问题困扰了很多天了,就是不知道怎么在视图里完成这个分页. 我用ci的时候,我看框架生成的链接都不对 Williamslife 发表于 2018-3-21 10:36
我用ci的时候,我看框架生成的链接都不对
解决了,还是segment的问题,得配置一下
页:
[1]