dongzai3917
2018-03-21 11:38
浏览 62
已采纳

如何在Codeigniter中对categoryid进行分页?

I have the following routing system in my

http://localhost/myproject/controller. 

When I filtring records using categoryid that have in second segment like:

http://localhost/myproject/controller/id.

I have a routing like this:

$route['routingcontroller/(:any)'] = 'controller/index/$1';

How my controller looks like

public function index()
{
    // Which records we want
    $id = $this->uri->segment(2);

    // Pagination starts
    $config['base_url'] = base_url().'routingcontroller/'.$id;
    $config['total_rows'] = $this->Product_model->count_total_records($id);
    $config['per_page'] = 12;

    // Customization
    $config['uri_segment'] = 2;
    $config['num_links'] = 2;
    //$config['use_page_numbers'] = TRUE;
    $config['enable_query_strings'] = TRUE;
    $config['page_query_string'] = TRUE;
    $config['query_string_segment'] = 'per_page';

    if ($this->uri->segment(2)) {
        $offset = $this->uri->segment(2);
    } else {
        $offset = 0;
    }

    $this->pagination->initialize($config);

    $data['configure'] = $this->Home_Model->configures();
    $data['main_menu'] = $this->Home_Model->main_menu();
    $data['social_media'] = $this->Home_Model->social_media();
    $data['testimonials'] = $this->Home_Model->testimonials();
    $data['category'] = $this->Product_model->category();
    $data['products'] = $this->Product_model->products($id, $config['per_page'], $offset);
    $data['main_content'] = 'viewfile';
    $this->load->view('includes/template', $data);
}

When I click pagination links that is display like

http://localhost/myproject/id/pageno

Then I get an error message like this:

404 Page Not Found

图片转代码服务由CSDN问答提供 功能建议

我的

  http中有以下路由系统:  //本地主机/ myproject的/控制器。  
   
 
 

当我使用第二段中的categoryid过滤记录时,如:

  http:// localhost /  myproject / controller / id。
   
 
 

我有这样的路由:

  $ route ['routingcontroller /  (:any)'] ='controller / index / $ 1'; 
   
 
 

我的控制器如何显示

  public function index()
 {
 //我们想要哪些记录
 $ id = $ this-> uri-> segment(2); 
 
 //分页开始
 $ config ['  base_url'] = base_url()。'routingcontroller /'.$ id; 
 $ config ['total_rows'] = $ this-> Product_model-> count_total_records($ id); 
 $ config ['per_page']  = 12; 
 
 //自定义
 $ config ['uri_segment'] = 2; 
 $ config ['num_links'] = 2; 
 // $ config ['use_page_numbers'] = TRUE; 
  $ config ['enable_query_strings'] = TRUE; 
 $ config ['page_query_string'] = TRUE; 
 $ config ['query_string_segment'] ='per_page'; 
 
 if($ this-> uri-&gt  ; segment(2)){
 $ offset = $ this-> ur  i-> segment(2); 
} else {
 $ offset = 0; 
} 
 
 $ this-> pagination-> initialize($ config); 
 
 $ data [  'configure'] = $ this-> Home_Model-> configure(); 
 $ data ['main_menu'] = $ this-> Home_Model-> main_menu(); 
 $ data ['social_media']  = $ this-> Home_Model-> social_media(); 
 $ data ['testimonials'] = $ this-> Home_Model-> testimonials(); 
 $ data ['category'] = $ this-  > Product_model-> category(); 
 $ data ['products'] = $ this-> Product_model-> products($ id,$ config ['per_page'],$ offset); 
 $ data  ['main_content'] ='viewfile'; 
 $ this-> load-> view('includes / template',$ data); 
} 
   
 
  

当我点击显示类似

  http:// localhost / myproject / id / pageno 
   
 \的分页链接时 n 

然后我收到如下错误消息:

  404找不到页面
   
 
  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douji9816 2018-03-21 12:09
    已采纳

    in route

    $route['routingcontroller/(:any)'] = 'controller/index/$1'; 
    $route['routingcontroller/(:any)/(:num)'] = 'controller/index/$1/$2';
    

    in controller

    public function index($id){
      // $id will be available
      // for page_no $this->uri->segment(3)
      // all code as it is
    }
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题