我在使用 Codeigniter 2.1 构建的网站上的搜索功能遇到问题。具体来说,我在分页和限制为每页 15 个项目时遇到问题。
我的控制器:
public function program_search()
{
if ($this->input->post('term')){
$this->front->set('title', 'Search Results');
$this->front->set('res' , $this->wc_search->search($this->input->post('term')));
$this->load->library('pagination');
$config['base_url'] = base_url().'/site/program_search_results/';
$this->db->where('JobRef',$this->input->post('term'));
$this->db->or_where('WorkType',$this->input->post('term'));
$this->db->or_where('Parish',$this->input->post('term'));
$this->db->or_where('Location',$this->input->post('term'));
$config['total_rows'] = $this->db->count_all_results('wc_program');
$config['per_page'] = 10;
$config['num_links'] = 20;
$config['full_tag_open'] = '<div id="pagination">';
$config['full_tag_close'] = '</div>';
$this->pagination->initialize($config);
$this->front->buffer('content', 'site/program_search_results');
$this->front->render();
}
else
{
$this->front->set('title', 'Program Search');
$this->front->buffer('content', 'site/program_search');
$this->front->render();
}
}
然后在我的模型中,我有:
public function search($term)
{
$data = array();
$this->default_select();
$this->db->like('JobRef', $term);
$this->db->or_like('Area', $term);
$this->db->or_like('Parish', $term);
$this->db->or_like('WorkType', $term);
$this->db->or_like('Location', $term);
$this->default_order_by();
//$this->db->limit(15);
$q = $this->db->get('wc_program');
if ($q->num_rows() > 0)
{
foreach ($q->result_array() as $row)
{
$data[] = $row;
}
}
$q->free_result();
return $data;
}
如何根据此代码使分页工作?我真的不想更改已经存在的代码,因为搜索工作正常。我只需要它在每页显示 15 条记录,无论搜索什么字词。