Sorting 带有排序选项的代码点火器分页

Sorting 带有排序选项的代码点火器分页,sorting,codeigniter,pagination,Sorting,Codeigniter,Pagination,我不确定我要问的是否可能。。我想可能不会,但我想我无论如何都会问 有没有办法重置分页 我有一个页面,上面有分页和排序选项。一切正常,但当其中一个排序选项被更改时,我希望将用户发送回第一页 (我很确定我这样做的方式根本不是获得我想要的结果的最佳方式,因此如果您有任何改进建议,请尽管提。) $array=explode(“quo,$this->uri->segment(4)); 如果(计数($array)>1){ $search_id=$array[1]; $start=$this->uri->se

我不确定我要问的是否可能。。我想可能不会,但我想我无论如何都会问

有没有办法重置分页

我有一个页面,上面有分页和排序选项。一切正常,但当其中一个排序选项被更改时,我希望将用户发送回第一页

(我很确定我这样做的方式根本不是获得我想要的结果的最佳方式,因此如果您有任何改进建议,请尽管提。)

$array=explode(“quo,$this->uri->segment(4));
如果(计数($array)>1){
$search_id=$array[1];
$start=$this->uri->segment(5);
$uri_段=5;
}否则{
$start=$this->uri->segment(4);
$uri_段=4;
$search\u id=null;
}
$config['per_page']=$this->settings['PRODUCTS_per_page'];
$config['total_rows']=$this->categories_model->get_num_rows($cat_id、$search_type、$search_data);
$query=$this->categories\u model->get\u category\u pages($cat\u id、$new\u limit、$new\u sort、$search\u id、$start、$this->settings['category\u ORDER']、$search\u type、$search\u data、$config['total\u rows'))
$config['base\u url']=base\u url()index.php/categories/view/”$类别识别号“/”$搜索字符串;
$config['uri_segment']=$uri_segment;
//分页的组合设置
$config['full_tag_open']='';
$config['full_tag_close']='';
//初始化分页
$this->pagination->initialize($config);

您可以在控制器中保留默认排序,该排序不会显示在url中。因此排序不会返回到第一页

样品

class Post extends Jewelery_Controller {

public function __construct() {
  parent::__construct();
  $this->load->model('Prime_model');
 }

  public function index($ordr_by = 'post_title', $sortr = 'ASC') {

  if ($this->uri->segment(6)) {
     $data['segment'] = $this->uri->segment(6);
  } else {
     $data['segment'] = 0;
  }

  if ($this->uri->segment(4)) {
     $ordr_by = $this->uri->segment(4);
  }

  if ($this->uri->segment(5)) {
     $sortr = $this->uri->segment(5);
  }

  $data['title'] = 'All Posts';
  $this->load->library('pagination');
  $config['base_url'] = base_url() . 'admin/post/index/' . $ordr_by . '/' . $sortr;
  $config['full_tag_open'] = '<div class="pagination"><ul>';
  $config['full_tag_close'] = '</ul></div>';
  $config['cur_tag_open'] = '<li class="active"><a href="">';
  $config['cur_tag_close'] = '</a></li>';
  $config['prev_tag_open'] = '<li>';
  $config['prev_tag_close'] = '</li>';
  $config['next_tag_open'] = '<li>';
  $config['next_tag_close'] = '</li>';
  $config['num_tag_open'] = '<li>';
  $config['num_tag_close'] = '</li>';
  $config['uri_segment'] = 6;
  $config['total_rows'] = $this->db->get('jewel_posts')->num_rows();
  $config['per_page'] = 10;
  $this->pagination->initialize($config);


  $data['post_info'] = $this->Prime_model->master_join('jewel_posts', 'jewel_jewelry_type', 'jewel_posts.jewelry_type = jewel_jewelry_type.jewelry_type_id', 'left', FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, $ordr_by, $sortr, $config['per_page'], $data['segment']);
  $this->load->view('admin/header', $data);
  $this->load->view('admin/post/index');
  $this->load->view('admin/footer');
}
class Post扩展了珠宝店\u控制器{
公共函数构造(){
父项::_构造();
$this->load->model('Prime_model');
}
公共功能索引($ordr\u by='post\u title',$sortr='ASC'){
如果($this->uri->segment(6)){
$data['segment']=$this->uri->segment(6);
}否则{
$data['segment']=0;
}
如果($this->uri->segment(4)){
$ordr_by=$this->uri->segment(4);
}
如果($this->uri->segment(5)){
$sortr=$this->uri->segment(5);
}
$data['title']='All Posts';
$this->load->library('pagination');
$config['base_url']=base_url().'admin/post/index/'.$ordr_by.'/'.$sortr;
$config['full_tag_open']='
    '; $config['full_tag_close']='
'; $config['cur_tag_open']='
  • ; $config['prev_tag_open']='
  • '; $config['prev_tag_close']='
  • ; $config['next_tag_open']='
  • '; $config['next_tag_close']='
  • ; $config['num_tag_open']='
  • '; $config['num_tag_close']='
  • ; $config['uri_segment']=6; $config['total_rows']=$this->db->get('jewel_posts')->num_rows(); $config['per_page']=10; $this->pagination->initialize($config); $data['post\u info']=$this->Prime\u model->master\u join('jewel\u posts','jewel\u jewelry\u type','jewelry\u type=jewell\u jewelry\u type.jewelry\u id','left',FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,$ordr\u-by,$sortr,$config['per\u page',$data['segment'); $this->load->view('admin/header',$data); $this->load->view('admin/post/index'); $this->load->view('admin/footer'); }
    您是否使用表格来显示页面上的数据?不,我不是。我只是循环浏览每个结果并将其返回到页面上。我建议将数据显示在表格中(使用css样式,最终用户甚至不会将其视为表格!),然后利用jQuery dataTables插件进行排序、搜索和分页。该插件支持服务器端分页,因此您的代码在某种程度上仍然是可重用的。
    class Post extends Jewelery_Controller {
    
    public function __construct() {
      parent::__construct();
      $this->load->model('Prime_model');
     }
    
      public function index($ordr_by = 'post_title', $sortr = 'ASC') {
    
      if ($this->uri->segment(6)) {
         $data['segment'] = $this->uri->segment(6);
      } else {
         $data['segment'] = 0;
      }
    
      if ($this->uri->segment(4)) {
         $ordr_by = $this->uri->segment(4);
      }
    
      if ($this->uri->segment(5)) {
         $sortr = $this->uri->segment(5);
      }
    
      $data['title'] = 'All Posts';
      $this->load->library('pagination');
      $config['base_url'] = base_url() . 'admin/post/index/' . $ordr_by . '/' . $sortr;
      $config['full_tag_open'] = '<div class="pagination"><ul>';
      $config['full_tag_close'] = '</ul></div>';
      $config['cur_tag_open'] = '<li class="active"><a href="">';
      $config['cur_tag_close'] = '</a></li>';
      $config['prev_tag_open'] = '<li>';
      $config['prev_tag_close'] = '</li>';
      $config['next_tag_open'] = '<li>';
      $config['next_tag_close'] = '</li>';
      $config['num_tag_open'] = '<li>';
      $config['num_tag_close'] = '</li>';
      $config['uri_segment'] = 6;
      $config['total_rows'] = $this->db->get('jewel_posts')->num_rows();
      $config['per_page'] = 10;
      $this->pagination->initialize($config);
    
    
      $data['post_info'] = $this->Prime_model->master_join('jewel_posts', 'jewel_jewelry_type', 'jewel_posts.jewelry_type = jewel_jewelry_type.jewelry_type_id', 'left', FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, $ordr_by, $sortr, $config['per_page'], $data['segment']);
      $this->load->view('admin/header', $data);
      $this->load->view('admin/post/index');
      $this->load->view('admin/footer');
    }