我有一个在codeigniter和页面中开发的网站我想使用分页。 问题是。我的网址现在像那样流淌:
http://site/index.php/tee/view_tee/?id=2
这是我进入控制器的代码:
$data['tee'] = $this->Tee_model->getTeeByUserId($this->input->get('id', TRUE));
$data['tee_like'] = $this->Tee_model->getLikeTeeByUserId($this->input->get('id', TRUE));
$data['user'] = $this->User_model->getUserById($this->session->userdata('id'));
$this->load->library('pagination');
$config['base_url'] = site_url().'/tee/view_tee/?id='.$this->input->get('id', TRUE);
$config['total_rows'] = count($data['tee']);
$config['per_page'] = 6;
$config['uri_segment'] = 3;
if (count($_GET) > 0) $config['suffix'] = '?' . http_build_query($_GET, '', "&");
$config['first_url'] = $config['base_url'].'?'.http_build_query($_GET);
$data['page_links']=$this->pagination->create_links();
$this->pagination->initialize($config);
$this->load->view('view_tee_view',$data);
使用此代码,当我点击我的分页链接时,我有这个网址:
http://site/index.php/tee/view_tee/?id=2/6?id=2
如果我再次点击,我有这个:
http://site/index.php/tee/view_tee/?id=2/6?id=2/6?id=2
这是我的HTML:
echo $this->pagination->create_links();
foreach($tee as $t){
// I have three div per lines
}
答案 0 :(得分:0)
添加此...
$config['page_query_string'] = TRUE;
删除此...
if (count($_GET) > 0) $config['suffix'] = '?' . http_build_query($_GET, '', "&");
$config['first_url'] = $config['base_url'].'?'.http_build_query($_GET);
[编辑]工作示例
$this->load->library('pagination');
$config['page_query_string'] = TRUE;
$config['base_url'] = site_url().'/tee/view_tee/?id='.$this->input->get('id', TRUE);
$config['total_rows'] = 200;
$config['per_page'] = 6;
$config['uri_segment'] = 3;
$this->pagination->initialize($config);
echo $this->pagination->create_links();