codeigniter分页不会更改视图上的数据

时间:2013-10-20 20:52:32

标签: php codeigniter pagination

我在CI的分页方面遇到了麻烦。 为什么视图上的数据不会改变?

查看:

<section class = "home">
<table>
    <?php foreach($players as $p): ?>
        <tr><td><?php echo $p->uname; ?></td><td><?php echo $p->ufbid; ?></td><td><?php echo $p->uemail; ?></td><td><?php echo $p->umobile; ?></td><td><?php echo $p->points; ?></td><td><?php echo $p->pticks; ?></td></tr>
    <?php endforeach; ?>
    <tr><?php echo $link; ?></tr>
</table>

控制器:

$perPage = 20;
    $pageConf = array(
        'base_url' => site_url('home/'),
        'total_rows' => $this->home_model->countPlayers(),
        'per_page' => $perPage,
        'uri_segment' => 2,
        //'use_page_numbers' =>TRUE,
    );

    $this->pagination->initialize($pageConf);
    $offset = $this->uri->segment(3) ? $this->uri->segment(3) : 0;
    $pData = $this->home_model->displayPlayers($perPage,$offset);
    $data = array(
        'players'=> $pData,
        'content'=> 'home',
        'link' => $this->pagination->create_links() 
    );
    $this->load->view('template/template',$data);

我已经在构造函数方法中加载了库。

来自控制器的记录集不会改变。我的uri段3就像这样&per_page=40

1 个答案:

答案 0 :(得分:0)

请尝试此代码,如果您使用的是分页类,可能会对您有所帮助 笨

 $perPage = 20;
 $pageConf = array(
    'base_url' => site_url('home/'),
    'total_rows' => $this->home_model->countPlayers(),
    'per_page' => $perPage,
    **'uri_segment' => 3,**
    //'use_page_numbers' =>TRUE,
 );
     $this->pagination->initialize($pageConf);
     $offset = $this->uri->segment(3) ? $this->uri->segment(3) : 0;
     $pData = $this->home_model->displayPlayers($perPage,$offset);
    $data = array(
    'players'=> $pData,
    'content'=> 'home',
    'link' => $this->pagination->create_links() 
    );
   $this->load->view('template/template',$data);