【问题标题】:How to make pagination with categoryid in Codeigniter?如何在 Codeigniter 中使用 categoryid 进行分页?
【发布时间】:2018-03-21 11:38:43
【问题描述】:

我有以下路由系统

http://localhost/myproject/controller. 

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

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

我有这样的路由:

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

我的控制器是什么样子的

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);
}

当我点击显示的分页链接时

http://localhost/myproject/id/pageno

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

404 Page Not Found

【问题讨论】:

    标签: php codeigniter pagination


    【解决方案1】:

    在路线中

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

    在控制器中

    public function index($id){
      // $id will be available
      // for page_no $this->uri->segment(3)
      // all code as it is
    }
    

    【讨论】:

    • 我的 URI 段是两个而不是三个
    • 好的,我现在没有收到任何错误,但问题是当我对页码进行分页时,它只会移动任何页面记录。
    • @mukesh_patel 您将能够获得 id 和 page_no,这完全取决于您如何使用它们。
    猜你喜欢
    • 2016-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多