【问题标题】:CodeIgniter Pagination Not Work At Other PageCodeIgniter 分页在其他页面不起作用
【发布时间】:2016-10-21 01:52:00
【问题描述】:

我在 CI 3.0 中启动了一个 Web 应用程序,一切正常,我的分页工作正常,但是有一个我无法解决的问题...

我的模特

//Model
    function jumlah(){
        return $this->db->count_all('buku');
    }

    function fetch_buku($limit,$start){
      $this->db->limit($limit,$start);
      $query=$this->db->get('buku');

      if($query->num_rows()>0){
        foreach ($query->result() as $row) {
          $data[]=$row;
        }
        return $data;
      }
      return false;
    }

我的控制器

//Controller
    function index(){

        //load data
        $data['title']="Data Buku";

        $config['base_url']=site_url('anggota/index/');
        $total_row=$this->m_buku->jumlah();
        $config['total_rows']=$total_row;
        $config['per_page']=$this->limit;
        $config['use_page_numbers']=TRUE;
        $config['uri_segment']=3;
        $this->pagination->initialize($config);

        $page=($this->uri->segment(3)) ? $this->uri->segment(3):0;;

        $data['buku']=$this->m_buku->fetch_buku($config['per_page'],$page);
        $data['pagination']=$this->pagination->create_links();
            $data['message']='';
            $this->template->display('buku/index',$data);
    }

我的看法

//View
    

    <?php echo $message;?>
        <Table class="table table-striped">
    <thead>
        <tr>
            <td>No.</td>
            <td>Image</td>
            <td>Kode Buku</td>
            <td>Judul</td>
            <td>Pengarang</td>
            <td>Klasifikasi</td>
            <td colspan="2"></td>
        </tr>
    </thead>
    <?php $no=0; foreach($buku as $row ): $no++;?>
    <tr>
        <td><?php echo $no;?></td>
        <td><img src="<?php echo base_url('assets/img/'.$row->image);?>" height="100px" width="100px"></td>
        <td><?php echo $row->kode_buku;?></td>
        <td><?php echo $row->judul;?></td>
        <td><?php echo $row->pengarang;?></td>
        <td><?php echo $row->klasifikasi;?></td>
        <td><a href="<?php echo site_url('buku/edit/'.$row->kode_buku);?>"><i class="glyphicon glyphicon-edit"></i></a></td>
        <td><a href="#" class="hapus" kode="<?php echo $row->kode_buku;?>"><i class="glyphicon glyphicon-trash"></i></a></td>
    </tr>
    <?php endforeach;?>
</Table>
        
        <?php echo $pagination;?>

我的问题是当我加载其他页面时,该页面上无法显示数据。但数据可以显示在第一页。

【问题讨论】:

    标签: php codeigniter pagination


    【解决方案1】:

    这样做

    在控制器中

    $total_row = $this->m_buku->jumlah();
    
    $config['base_url'] = base_url() . 'anggota/index/'; # make sure site is load without index.php
    $config['total_rows'] = $total_row;
    $config['per_page'] = '12'; # provide some number here
    $config['uri_segment'] = 2; # this should be 2. If index.php is there then 3
    
    $this->pagination->initialize($config);
    
    $page = ($this->uri->segment(2)) ? $this->uri->segment(2) : 0;
    
    $data['links'] = $this->pagination->create_links();
    

    可见

    echo $links
    

    确保网站在没有 index.php 的情况下加载

    【讨论】:

      【解决方案2】:

      如果您将$config['use_page_numbers'] 设置为 TRUE,那么它将转换偏移量。尝试将值更改为 FALSE。假设您的 $config['per_page'] 是 10,那么它应该在您的 URL 中显示类似这样的内容:anggota/index/anggota/index/10anggota/index/20。如果设置为 TRUE,那么您的 URL 可能看起来像 anggota/index/1anggota/index/2anggota/index/3 等。

      【讨论】:

        猜你喜欢
        • 2019-08-01
        • 2014-02-03
        • 2018-02-02
        • 2016-01-03
        • 1970-01-01
        • 1970-01-01
        • 2014-01-13
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多