【发布时间】:2014-04-13 07:51:12
【问题描述】:
我需要使用获取参数进行分页。在方法中,我编写了如下代码。
public function index($offset = 0) {
$data['title_for_layout'] = 'Apartment Advertisement - Search';
// Pagination config
$this->load->library('pagination');
$pagination['enable_query_strings'] = true;
$pagination['page_query_string'] = true;
$pagination['allow_get_array'] = true;
$pagination['first_url'] = base_url('search');
$pagination['base_url'] = $config['first_url'];
$pagination['total_rows'] = $this->aa_movies->no_of_search_movies();
$data['no_of_results'] = $pagination['total_rows'];
$pagination['use_page_numbers'] = TRUE;
$pagination['per_page'] = 20;
// Initialize pagination
$this->pagination->initialize($pagination);
// Offset
$offset = 20 * $offset;
// Get apartments
$data['apartments'] = $this->aa_movies->search_movies($this->input->get('keyword'), $this->input->get('city'), $this->input->get('locations'), $offset);
$this->load->view($this->config->item('index_search_view'), $data);
}
在视图中
<?php echo form_open(base_url('search'), array('method' => 'get'); ?>
<?php echo $this->pagination->create_links(); ?>
<?php echo form_close(); ?>
所以分页网址看起来像
http://localhost/reelstubs/search/1
但我想在分页网址如下
http://localhost/reelstubs/search?keyword=complex&city=bangalore&page=1
即使我尝试通过包含 $_SERVER['REQUEST_URI'] 来更改分页 base_url。但网址看起来像
http://localhost/reelstubs/search?keyword=complex&city=bangalore/1
所以我没有使用$this->uri->segment(); 获得页面,请帮助我克服这个问题。我已经浪费了2天了。这项工作将受到更多赞赏。
【问题讨论】:
-
不要使用
$this->uri->segment();,尝试类似 thsi$this->input->get("page")
标签: codeigniter pagination codeigniter-2 codeigniter-url