0

我在多个 Codeigniter 项目中工作,并找到了这种在不丢失过滤器和订单的情况下对搜索进行分页的方式。

您可以通过这种方式为分页链接定义后缀:

$config['suffix'] = YOUR_SUFFIX

例子:

网址:http ://www.test_store.com/products/index/search/foo/order/low_price

// Parsing the URI
$uri = $this->uri->uri_to_assoc(3);

$page     = !empty($uri['page'])   ? $uri['page']   : 1;
$order    = !empty($uri['order'])  ? $uri['order']  : false;
$search   = !empty($uri['search']) ? rawurldecode($uri['search']) : false;

// Search paginated
$this->Product->limit  = $per_page;
$this->Product->offset = ($page - 1) * $per_page;
$this->Product->order  = $order;
$this->Product->search = $search;

$products = $this->Product->get_all();

// Pagination config
$config['base_url']         = site_url('products/index/page');
$config['total_rows']       = $this->Product->count_all();
$config['uri_segment']      = 4;
$config['num_links']        = 5;
$config['use_page_numbers'] = TRUE;
$config['per_page']         = $per_page; 

// Add a suffix to pagination links (The key 'suffix' isn't documented apparently)
unset($uri['page']); // Don't needed
$config['suffix'] = !empty($uri) ? '/'. $this->uri->assoc_to_uri($uri) : ''; 

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

$pagination = $this->pagination->create_links();

接受更正!

PD:我是阿根廷人,我的英语水平有点差

4

0 回答 0