我有一个具有以下设置的过滤器选项:
选项 1 >显示:每页 20 个或每页 50 个或每页全部 - 这是在下拉列表中(默认每页 10 个)
选项 2 >排序方式:从低到高或从高到低或字母 AZ 或字母 ZA(默认 AZ)
选项 3 >分页这就完成了。
我的登陆页面是:域名/衬衫
我已经完成了分页,我的 url 看起来像:domain-name/shirts/page/1
我要实现的url: domain-name/shirts/page/1/perpage/50/sortby/ZA
但在现实世界中,最终用户以不同的方式选择此选项:
场景一: 示例:先排序,后页码第二,url示例:domain-name/shirts/perpage/50/page/1 *
(或者)
场景二: 示例:先排序后页码第二,url示例:domain-name/shirts/perpage/50/page/1
(或者)
场景3: 示例:先排序后页码第二,url示例:domain-name/shirts/sortby/ZA/perpage/50/page/1
我希望 url 结构始终按以下顺序排列 - 不管如何选择这些选项:
- 域名/衬衫/页面/1/sortby/ZA
- 域名/shirts/page/1/perpage/50/
- 域名/衬衫/每页/50/sortby/ZA
- 域名/shirts/page/1/perpage/50/sortby/ZA
我如何实现这一目标?
我的控制器代码 - index()
$all_shirts = $this->shirts_model->get_shirts_count();
$total_rows = $all_shirts;
$config = array();
$config['base_url'] = base_url()."shirts";
$config['per_page'] = 5;
$config['total_rows'] = $total_rows;
$config['use_page_numbers'] = false;
$config['page_query_string'] = FALSE;
$config['first_url'] = '1';
$config['first_link'] = 'First';
$config['first_url'] = base_url().'shirts';
$config['last_link'] = FALSE;
$config['next_link'] = 'Next >';
$config['next_tag_open'] = ' <span class="next">';
$config['next_tag_close'] = '</span>';
$config['prefix'] = '/page/';
$config['prev_tag_open'] = '<span class="prev">';
$config['prev_tag_close'] = '</span> ';
$config['cur_tag_open'] = ' <b>';
$config['cur_tag_close'] = '</b>';
if($this->uri->segment(3) < '3')
{
$config['prev_link'] = FALSE;
}
else
{
$config['prev_link'] = '< Previous';
}
$this->pagination->initialize($config);
$data = array();
$data['Shirts_pagination'] = $this->shirts_model->get_shirts_limit($config['per_page'],$this->uri->segment(3,0),'');
$data["links"] = $this->pagination->create_links();
$data['show_all'] = 0;
$this->load->view('shirts_view.php', $data);
}