url上带参数的分页问题
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();?>
http://imgsrc.baidu.com/forum/w%3D580/sign=4e4affad6d81800a6ee58906813533d6/8694a4c27d1ed21b91e628c7ac6eddc451da3fe0.jpg
显示效果:
http://imgsrc.baidu.com/forum/w%3D580/sign=c9c059720d3387449cc52f74610ed937/b3b7d0a20cf431adf40b441b4a36acaf2edd9832.jpg
这是鼠标放到2上显示的链接http://imgsrc.baidu.com/forum/w%3D580/sign=4dd7b556eaf81a4c2632ecc1e72b6029/0df431adcbef76090ad29ebd2fdda3cc7cd99e32.jpg
这是3的链接http://imgsrc.baidu.com/forum/w%3D580/sign=6bb289b3cc11728b302d8c2af8fdc3b3/d043ad4bd11373f038b069bda50f4bfbfbed0400.jpg
为什么 1 2 3 > 的链接是错的?应该是/index.php/home/category/1/2、/index.php/home/category/1/3啊?
求高手解答!!{:soso_e136:}
怕大家看不清,截了编辑器的图。
http://imgsrc.baidu.com/forum/w%3D580/sign=cddc48cb8c1001e94e3c1407880e7b06/48540923dd54564efc48e51bb2de9c82d1584fe6.jpg
http://imgsrc.baidu.com/forum/w%3D580/sign=161588235d6034a829e2b889fb1349d9/9e3df8dcd100baa1422146994610b912c8fc2e86.jpg
http://imgsrc.baidu.com/forum/w%3D580/sign=323c47e283025aafd3327ec3cbedab8d/86d6277f9e2f0708cb172b22e824b899a901f286.jpg http://imgsrc.baidu.com/forum/w%3D580/sign=cddc48cb8c1001e94e3c1407880e7b06/48540923dd54564efc48e51bb2de9c82d1584fe6.jpg http://imgsrc.baidu.com/forum/w%3D580/sign=161588235d6034a829e2b889fb1349d9/9e3df8dcd100baa1422146994610b912c8fc2e86.jpg http://imgsrc.baidu.com/forum/w%3D580/sign=323c47e283025aafd3327ec3cbedab8d/86d6277f9e2f0708cb172b22e824b899a901f286.jpg 还不错的呢!!!呵呵! conqueror 发表于 2013-2-18 13:22 static/image/common/back.gif
还不错的呢!!!呵呵!
没人来解决问题啊!!!:'( 你的图片我电脑里看不到,用手机上的看到的貌似是页2为3,页3为6,设置你的config['uri_segment']=4,试试 “为什么 1 2 3 > 的链接是错的?应该是/index.php/home/category/1/2、/index.php/home/category/1/3啊?”至于这个呢,设置config['use_page_numbers'] = TRUE; tankangwen 发表于 2013-2-19 12:47 static/image/common/back.gif
“为什么 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 给少没了,
大侠知道哪的问题么?
页:
[1]
2