用户
 找回密码
 入住 CI 中国社区
搜索
12
返回列表 发新帖
楼主: codeigniter_lht
收起左侧

url上带参数的分页问题

[复制链接]
 楼主| 发表于 2013-2-19 15:25:59 | 显示全部楼层
tankangwen 发表于 2013-2-19 12:45
你的图片我电脑里看不到,用手机上的看到的貌似是页2为3,页3为6,设置你的config['uri_segment']=4,试试 ...

                        $config['base_url']                =        base_url('index.php/home/category');
                        $config['total_rows']        =        $this->newsmodel->count_rows($this->uri->segment(3));
                        $config['per_page']                =        3;
                        $config['uri_segment']=        4;
                        $config['use_page_numbers'] = TRUE;


回楼上哥们的话,uri_segment加了,貌似还不好使。
是不是还缺什么东西着了
 楼主| 发表于 2013-2-20 10:46:20 | 显示全部楼层
我搞定了。

$config['base_url']                =        base_url('index.php/home/category/'.$this->uri->segment(3));

加上$config['base_url']里面加上.$this->uri->segment(3)即可。

 楼主| 发表于 2013-2-20 10:49:50 | 显示全部楼层
function category(){
                        $data['header_title']        =        "栏目列表";
                        $this->load->model('newsmodel');
                        $this->load->library('pagination');
                        $config['base_url']                =        base_url('index.php/home/category/'.$this->uri->segment(3));
                        $config['total_rows']        =        $this->newsmodel->count_rows($this->uri->segment(3));
                        $config['per_page']                =        3;
                        $config['uri_segment']=        4;
                        $config['use_page_numbers'] = TRUE;
                       
                        $offset        =        $this->uri->segment(4,0);
                        /*或者
                        $pageNUM        =        $this->uri->segment(4)?$this->uri->segment(4):1;
                        if ($pageNUM==1){
                                $offset        =        0;
                        }else{
                                $offset        =        $config['per_page']*($this->uri->segment(4)-1);
                        }
                        */
                       
                        $this->pagination->initialize($config);
                        $data['category']        =        $this->newsmodel->get_category();
                        $data['get_category_name']        =        $this->newsmodel->get_category_name($this->uri->segment(3));
                        $data['get_article']        =        $this->newsmodel->get_article($this->uri->segment(3),$config['per_page'],$offset);
                        $this->load->view('newssys/header',$data);
                        $this->load->view('newssys/category');
                        $this->load->view('newssys/footer');
                }
发表于 2013-2-20 13:01:43 | 显示全部楼层
codeigniter_lht 发表于 2013-2-19 15:21
这个是正解!

可是,现在2、3对了,前面的链接少了category/1的参数,现在放在2、3上的url链接是这样:

一看就知道我不是大侠了,我刚学2个月,呵呵...这帖子的回复还是处女贴呢...你确实搞错了,建议你自己看看代码.$this->uri->segment(3)这是分类的ID是不?$config['base_url']                =        base_url('index.php/home/category')这里是否少了什么?你的分类ID没传过去吧('index.php/home/category/$id')这是我乱给你的变量$id。自己再看看...
发表于 2013-2-20 13:04:55 | 显示全部楼层
我之前说的“你的图片我电脑里看不到,用手机上的看到的貌似是页2为3,页3为6,设置你的config['uri_segment']=4,试试”,就是因为看到你的url第三、第四个字段没弄好...
发表于 2013-6-20 11:40:37 | 显示全部楼层
codeigniter_lht 发表于 2013-2-19 15:21
这个是正解!

可是,现在2、3对了,前面的链接少了category/1的参数,现在放在2、3上的url链接是这样:

怎么CI都有这个问题,一同求解

本版积分规则