与codeigniter和bootstrap链接的分页不正确

时间:2014-03-07 14:34:37

标签: codeigniter twitter-bootstrap pagination

我在我的一个codiegniter页面中使用了分页,我想在bootstrap类中显示分页链接,链接在第一页上正确显示但是当我点击link2时链接比没有正确显示。请给我看我怎样才能调整它们。 这是我的观点页面。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<base href="<?php echo base_url()?>" />
 <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>User Handling</title>

    <!-- Bootstrap -->
    <link href="<?php echo base_url();?>css/bootstrap.min.css" rel="stylesheet">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body class="container">
<div class="row">
<div class="col-lg-12">
<?php
if(isset($new_post))
{
    foreach($new_post as $row)
    {
        echo '<h1>'.$row->tittle.'</h1>';

        echo '<p style="background-color:#CCC;">'.$row->post.'</p>';
        $row->id;
        echo '<a href="index/post_edit/'.$row->id.'">Edit</a>&nbsp;&nbsp;';
        echo '<a href="index/delete_post/'.$row->id.'">Delete</a>';
        echo '<br/>';

    }
}

问题在于分页链接

if(isset($link)){
 echo '<ul class="pagination"><li>'.$link.'</li></ul>';
 echo '<br/>';
}
else{
    echo'no link have been fired';
}
?>
<a href="<?php echo 'index';?>"><button class="btn btn-large btn-success">Home</button></a>
</div>
</div>
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="<?php echo base_url();?>js/bootstrap.min.js"></script>
</body>

我传递这些链接的控制器功能。

function show_post()
   {
     $config['base_url'] = base_url().'index/show_post';
      $config['total_rows'] = $this->user->record_count();
      $config['per_page'] = 3; 
      $config['uri_segment']=3;
      $this->pagination->initialize($config); 
      $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;

      $data['link']=$this->pagination->create_links();
      $data['new_post']=$this->user->getpost($config['per_page'],$page);


     $this->load->view("post",$data);
   }

分页正确的第一页。 correct pagination view

分页不正确的第二页。 enter image description here

2 个答案:

答案 0 :(得分:3)

不是codeigniter的分页类专家,但我想你应该阅读标题为&#34;自定义分页的部分,&#34;和&#34;添加封闭标记&#34;

http://ellislab.com/codeigniter/user-guide/libraries/pagination.html

如果你想改变链接的显示方式(html包围它们等等),我相信你需要使用提供的配置选项。

看看是否有帮助。

好了编辑这个为你添加一些代码......虽然这在文档中都有解释。

// If you want to wrap your pagination in something
$config['full_tag_open'] = '<ul class="pagination">';
$config['full_tag_close'] = '</ul>';

// If you want to wrap the "go to first" link
$config['first_link'] = 'First';
$config['first_tag_open'] = '<li class="whateverboostrap">';
$config['first_tag_close'] = '</li>';

// If you want to wrap the "go to last" link
$config['last_link'] = 'Last';
$config['last_tag_open'] = '<li class="whateverboostrap">';
$config['last_tag_close'] = '</li>';

// If you want to wrap the next link
$config['next_link'] = 'Next';
$config['next_tag_open'] = '<li class="whateverboostrap">';
$config['next_tag_close'] = '</li>';

// If you want to wrap the previous link
$config['prev_link'] = 'Last';
$config['prev_tag_open'] = '<li class="whateverboostrap">';
$config['prev_tag_close'] = '</li>';

// Wrap/style active link
$config['cur_tag_open'] = '<li class="active whateverboostrap">';
$config['cur_tag_close'] = '</li>';

// Wrap the 'digit' link.
$config['num_tag_open'] = '<li class="whateverboostrap">';
$config['num_tag_close'] = '</li>';

答案 1 :(得分:1)

在此链接中使用codiegniter和bootstrap的分页非常漂亮,请点击pagination with codiegniter and bootstrap

的链接

所有这些都是由作者完成的,你只需要调整代码,如果它不能正常工作,它肯定会让我知道。