用户
 找回密码
 入住 CI 中国社区
搜索
查看: 3706|回复: 15
收起左侧

url上带参数的分页问题

[复制链接]
发表于 2013-2-17 17:38:02 | 显示全部楼层 |阅读模式
Controller:
function category(){
                        $data['header_title']        =        "栏目列表";
                        $this->load->model('newsmodel');
                        $this->load->library('pagination');
                        $config['base_url']                =        base_url('index.php/home/category');
                        $config['total_rows']        =        $this->newsmodel->count_rows($this->uri->segment(3));
                        $config['per_page']                =        3;
                        $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');
                }


Model:
function get_article($category_id,$per_page,$offset){
                        $query        =        $this->db->get_where('article',array('category_id'=>$category_id),$per_page,$offset);
                        return $query->result();
                }
               
                function count_rows($category_id){
                        $query        =        $this->db->query("select * from article where category_id = $category_id");
                        $rows                =        $query->result();
                        return count($rows);
                }


View:
<ul>
<?php foreach ($get_article as $rows):?>
<li><?=anchor('home/article/'.$rows->id,$rows->title)?></li>
<?php endforeach;?>
</ul>
<?php echo $this->pagination->create_links();?>



显示效果:

这是鼠标放到2上显示的链接
这是3的链接

为什么 1 2 3 > 的链接是错的?应该是/index.php/home/category/1/2、/index.php/home/category/1/3啊?

求高手解答!!{:soso_e136:}


 楼主| 发表于 2013-2-17 17:40:38 | 显示全部楼层
怕大家看不清,截了编辑器的图。



 楼主| 发表于 2013-2-17 17:40:56 | 显示全部楼层
 楼主| 发表于 2013-2-17 17:41:11 | 显示全部楼层
 楼主| 发表于 2013-2-17 17:41:33 | 显示全部楼层
发表于 2013-2-18 13:22:49 | 显示全部楼层
还不错的呢!!!呵呵!
 楼主| 发表于 2013-2-19 11:03:51 | 显示全部楼层
conqueror 发表于 2013-2-18 13:22
还不错的呢!!!呵呵!

没人来解决问题啊!!!
发表于 2013-2-19 12:45:32 | 显示全部楼层
你的图片我电脑里看不到,用手机上的看到的貌似是页2为3,页3为6,设置你的config['uri_segment']=4,试试
发表于 2013-2-19 12:47:21 | 显示全部楼层
“为什么 1 2 3 > 的链接是错的?应该是/index.php/home/category/1/2、/index.php/home/category/1/3啊?”至于这个呢,设置config['use_page_numbers'] = TRUE;
 楼主| 发表于 2013-2-19 15:21:36 | 显示全部楼层
tankangwen 发表于 2013-2-19 12:47
“为什么 1 2 3 > 的链接是错的?应该是/index.php/home/category/1/2、/index.php/home/category/1/3啊? ...

这个是正解!

可是,现在2、3对了,前面的链接少了category/1的参数,现在放在2、3上的url链接是这样:
http://localhost/CI/index.php/home/category/2
http://localhost/CI/index.php/home/category/3

把 /1 给少没了,


大侠知道哪的问题么?

本版积分规则