suzhisheng 发表于 2015-6-23 12:59:09

CI分页问题

本帖最后由 suzhisheng 于 2015-6-23 13:02 编辑

代码
function index($offset=''){
                //设置分页的行数,当为假时,即设为''或者0,或者null则不分页
                $limit = 2;
                $config['base_url']=site_url('message2/index/');
                $config['total_rows']=$this->Message_model->count_table();//
                $config['per_page']=$limit;
                //$config['uri_segment']=3;
                //这几行行为可选设置
                $config['first_link']='首页';
                $config['last_link']='尾页';
                $config['next_link']='下一页>';
                $config['prev_link']='<上一页';
                $config['num_links']=2;//放在你当前页码的前面和后面的"数字"链接的数量
                $this->pagination->initialize($config);

                //$offset=$this->uri->segment(3);

                //放到数组中,传给视图
                $data['pagination']=$this->pagination->create_links();
                $data['query']=$this->Message_model->show($limit,$offset);//对模型的调用,应该写在控制器中,控制器起到中间人的作用
                $this->load->view('message_view',$data);
      }


结果:URL不对啊
<a href="http://localhost/ciproject/index.php/message2/index.html/2">2</a>
<a href="http://localhost/ciproject/index.php/message2/index.html/4">3</a>
<a href="http://localhost/ciproject/index.php/message2/index.html/2>下一页</a><a href="http://localhost/ciproject/index.php/message2/index.html/6">尾页</a>


那个后缀名我去掉了,不知道怎么还有。

suzhisheng 发表于 2015-6-23 16:09:12

本帖最后由 suzhisheng 于 2015-6-23 16:10 编辑

转:http://blog.csdn.net/rainday0310/article/details/6270458由于CODE的遗留问题,分页类是不支持URL自定义后缀的,假设你设定URL自定义后缀是.html的话,分页产生的链接是这样的:http://www.xx.com/class/method/par1/par2.htm/page    [其中page是页数]
而我们的理想要求是:http://www.xx.com/class/method/par1/par2/page.html   我们可以简单修改下就可以做到了,
在:Pagination类的create_links方法中在最后即return $output; 前加上三行代码:
$url_suffix=$CI->config->item('url_suffix');   
$output=str_replace($url_suffix,'',$output);   
$output=preg_replace("///(+)/"/","///1".$url_suffix."/"",$output);   
这样就可以获得在分页情况下的:http://www.xx.com/class/method/par1/par2/page.html 理想类型

suzhisheng 发表于 2015-6-23 13:00:11

URL:

suzhisheng 发表于 2015-6-23 13:00:36

<a >2</a>&nbsp;<a >3</a>&nbsp;<a >下一页></a>&nbsp;&nbsp;<a >尾页</a>
页: [1]
查看完整版本: CI分页问题