codeigniter分页create_links()

时间:2012-07-08 06:51:27

标签: php codeigniter pagination

问题在于,在分页中,我还没有显示数据库的东西,但问题不在于此。

问题是我已经显示了页面链接,但当我点击第2页的链接时,它会转到    

http://127.0.0.1:8887/codeigniter-tests/index.php/pagination/index/127.0.0.1:8887/codeigniter-tests/index.php/pagination/index/5

正如您所看到的,链接基本上重复了两次,现在,如果我在第2页点击1,则需要我这样做     

http://127.0.0.1:8887/codeigniter-tests/index.php/pagination/index/127.0.0.1:8887/codeigniter-tests/index.php/pagination/index/127.0.0.1:8887/codeigniter-tests/index.php/pagination/index/

所以你可以看到,现在它写了三次,如果我点击这个页面上的2它再次附加网址并带我到那里:/

现在我想问为什么会发生这种情况???

下面是代码:_

控制器(pagination.php)     

class Pagination扩展了CI_Controller {

function index() {
    $this->load->library('pagination');

    $config['base_url'] = '127.0.0.1:8887/codeigniter-tests/index.php/pagination/index/';
    $config['total_rows'] = $this->db->get('data')->num_rows;
    $config['per_page'] = 5;
    $config['num_links'] = 10;
    $config['uri_segment'] = 3;

    $this->pagination->initialize($config);

    $data['records'] = $this->db->get('data', $config['per_page'], $config['uri_segment']);
    $this->load->view('pagination_view', $data);


}

}

这是视图(pagination_view.php):_

<html>  
<head>  
    <title>CI Pagination</title>  
</head>  
<body>  
    <h1>Pagination With CI</h1> 
    <?php
        echo $this->pagination->create_links();
    ?>
</body>  
</html>  

只是一些额外的信息,如果我将$ config ['base_url']设置为空,它链接到     

127.0.0.1:8887/5

任何帮助都会受到赞赏,这是一个错误吗?

2 个答案:

答案 0 :(得分:1)

尝试使用它:

$config['base_url'] = '/codeigniter-tests/index.php/pagination/index/';

答案 1 :(得分:1)

我认为$config['base_url']不支持不完整的网址。尝试添加协议位或只留下路径:

$config['base_url'] = 'http://127.0.0.1:8887/codeigniter-tests/index.php/pagination/index/';
$config['base_url'] = '/codeigniter-tests/index.php/pagination/index/';