我想创建一个包含搜索表单中的字符串和来自分页
的页面的URL例如,我的基本网址为example.com/search
显示搜索结果时,它将为example.com/search/?s=keyword
,当显示下一页的搜索结果时,第二页的搜索结果为example.com/search/?s=term&p=2
,依此类推
如何在CodeIgniter中制作它?
答案 0 :(得分:2)
试试这个。这里在网址
中使用了page
而不是p
$keyword = trim($this->input->get('s', TRUE));
$this->load->library('pagination');
$config['total_rows'] = $this->db->get('table_name')->num_rows();
$config['per_page'] = 10;
$config['num_links'] = 5;
$config['enable_query_strings'] = TRUE;
$config['use_page_numbers'] = TRUE;
$config['query_string_segment'] = 'page';
$config['page_query_string'] = TRUE;
$config['base_url'] = site_url('search/index/?s=' . $keyword);
$config['full_tag_open'] = '<ul class="pagination">';
$config['full_tag_close'] = '</ul>';
if ($this->input->get('page')) {
$sgm = (int) trim($this->input->get('page'));
$segment = $config['per_page'] * ($sgm - 1);
} else {
$segment = 0;
}
$this->pagination->initialize($config);
// your query
$query = $this->db->select('*')->from('table_name')->limit($config['per_page'], $segment)->get();
现在您的网址与您在问题中提到的网址相同