0

我有一个用 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
}
4

1 回答 1

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();
于 2013-05-27T16:53:09.080 回答