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

发布于 2024-11-06 21:17:05 字数 1304 浏览 1 评论 0原文

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

有什么办法可以重置分页吗?

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

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

        $array =  explode ("_",$this->uri->segment(4));

        if(count($array) > 1){
            $search_id = $array[1];
            $start = $this->uri->segment(5);
            $uri_segment = 5;
        }else{
            $start = $this->uri->segment(4);
            $uri_segment = 4;
            $search_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_model->get_category_pages($cat_id, $new_limit, $new_sort, $search_id, $start, $this->settings['CATEGORY_ORDER'], $search_type, $search_data,  $config['total_rows']))

$config['base_url'] = base_url() . 'index.php/categories/view/' . $cat_id ."/" . $search_string ;

 $config['uri_segment'] = $uri_segment;

 //Congig settings for pagination
 $config['full_tag_open'] = '<div id="pagination" style= "clear:both;">';
 $config['full_tag_close'] = '</div>';

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

I'm not sure if what I'm about to ask is possible or not.. I'm thinking probably not but I thought I would ask anyways.

Is there any way to reset the pagination?

I've got a page with has pagination and sort option on it. Everything works fine but when one of the sort options is changed I would like to send the user back to the first page.

(I'm pretty sure the way I'm doing this isn't at all the best way to get the result I want so if you have any suggestions for improvements please feel free.)

        $array =  explode ("_",$this->uri->segment(4));

        if(count($array) > 1){
            $search_id = $array[1];
            $start = $this->uri->segment(5);
            $uri_segment = 5;
        }else{
            $start = $this->uri->segment(4);
            $uri_segment = 4;
            $search_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_model->get_category_pages($cat_id, $new_limit, $new_sort, $search_id, $start, $this->settings['CATEGORY_ORDER'], $search_type, $search_data,  $config['total_rows']))

$config['base_url'] = base_url() . 'index.php/categories/view/' . $cat_id ."/" . $search_string ;

 $config['uri_segment'] = $uri_segment;

 //Congig settings for pagination
 $config['full_tag_open'] = '<div id="pagination" style= "clear:both;">';
 $config['full_tag_close'] = '</div>';

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

隔岸观火 2024-11-13 21:17:05

您可以在控制器中保留默认排序,该排序不会显示在 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');
}

you may keep a default sorting in controller which will not show in url.so sorting will not back to the first page.

a sample

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');
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文