Codeigniter中的分页无法正常工作

时间:2014-08-12 10:26:10

标签: codeigniter pagination

当我在codeigniter中添加分页时,它会显示每个页面上的所有记录。 我不知道问题所在:这是我的代码: 控制器:

public function clients(){
     $this->load->model('mindex');
     $this->load->library('pagination');
     $dataclient['records'] = $this->mindex->clientRecords();
     $this->load->helper('url');
     //pagination configuration
     $config['base_url'] = site_url('cpromo/cindex/clients'); 
     $config['total_rows'] = count($dataclient['records']);
     $config['per_page'] = 2;
     $config["uri_segment"] = 4;

     $this->pagination->initialize($config);
     $this->load->view('vpromo/clients.php',$dataclient , $config['total_rows'] ,    $config['per_page'] , $page );

    }

以下是我的观点:

            <?php foreach( $records as $row ): ?>
               <h3><?php echo $row->name; ?></h3>
                <p><?php echo $row->description; ?></p>
               <?php endforeach; ?>
                  <?php echo  $this->pagination->create_links(); ?>

提前致谢

2 个答案:

答案 0 :(得分:1)

你不在sql中使用偏移量和限制只查询所有记录 - &gt;发送到页面

这是一个很好的教程;-) Pagination with CodeIgniter

答案 1 :(得分:0)

public function set_pagination($base_url, $total_rows, $per_page)
    {
        $config['base_url'] = $base_url;
        $config['total_rows'] = $total_rows;
        $config['per_page'] = $per_page;

        $config['use_page_numbers'] = TRUE;
        $config['reuse_query_string'] = TRUE;

        $config['full_tag_open'] = '<ul class="pagination">';
        $config['full_tag_close'] = '</ul>';

        $config['first_link'] = FALSE;
        $config['first_tag_open'] = '<li class="page-item">';
        $config['first_tag_close'] = '</li>';

        $config['last_link'] = false;
        $config['last_tag_open'] = '<li class="lastlink">';
        $config['last_tag_close'] = '</li>';

        $config['next_link'] = 'Next';
        $config['next_tag_open'] = '<li class="page-item">';
        $config['next_tag_close'] = '</li>';

        $config['prev_link'] = 'Prev';
        $config['prev_tag_open'] = '<li class="page-item">';
        $config['prev_tag_close'] = '</li>';

        $config['cur_tag_open'] = '<li class="page-item active"><span class="page-link">';
        $config['cur_tag_close'] = '</span></li>';

        $config['num_tag_open'] = '<li class="page-item">';
        $config['num_tag_close'] = '</li>';

        $config['attributes'] = array('class' => 'page-link');

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

        return $this->pagination->create_links();
    }