在PHP codeigniter中分页显示错误

时间:2017-09-20 05:53:55

标签: php codeigniter pagination

我正在开发一个需要分页的项目,我尝试使用此代码它没有显示任何错误,但是第一页加载5条记录,而我点击下一页重新加载并仅显示前5条记录。

这是我的控制器

public
function listing($offset = 0) {

    $config['total_rows'] = $this - > gt_paging_model - > totalpage();

    $config['base_url'] = base_url().
    "index.php/gt_package/listing";
    $config['per_page'] = 5;
    $config['uri_segment'] = '2';

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

    $config['first_link'] = '« First';
    $config['first_tag_open'] = '<li class="prev page">';
    $config['first_tag_close'] = '</li>';

    $config['last_link'] = 'Last »';
    $config['last_tag_open'] = '<li class="next page">';
    $config['last_tag_close'] = '</li>';

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

    $config['prev_link'] = '← Previous';
    $config['prev_tag_open'] = '<li class="prev page">';
    $config['prev_tag_close'] = '</li>';

    $config['cur_tag_open'] = '<li class="active"><a href="">';
    $config['cur_tag_close'] = '</a></li>';

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


    $this - > pagination - > initialize($config);
    $data["links"] = $this - > pagination - > create_links();

    $query = $this - > gt_paging_model - > getpage(5, $this - > uri - > segment(2));

    $data['records'] = null;

    if ($query) {
        $data['records'] = $query;
    }

    $this - > load - > view('admin/package/package_listing', $data);
}

这是我的模特

    class gt_paging_model extends CI_Model {

    function __construct() {
        parent::__construct();
    }

    function getpage($limit = null, $offset = NULL) {
        $this - > db - > limit($limit, $offset);
        $query = $this - > db - > get('gt_package');
        return $query - > result();
    }

    function totalpage() {
        return $this - > db - > count_all_results('gt_package');
    }
}

这是我在视图中调用的方式

<?php if (isset($links)) { ?>
            <?php echo $links ?>
        <?php } ?>

1 个答案:

答案 0 :(得分:2)

用于bootstrap分页 按照一些步骤

pagination.php

中创建application/config/pagination.php

粘贴代码

<?php

$config['full_tag_open']      ='<ul class="pagination">';
$config['full_tag_close']     ='</ul>';
$config['cur_tag_open']       ='&nbsp;<li class="active"><a href="#">';
$config['cur_tag_close']      ='</a></li>';
$config['num_tag_open']         ="<li>";
$config['num_tag_close']         ="</li>";
$config['prev_tag_open']         ="<li>";
$config['prev_tag_close']         ="</li>";
$config['next_tag_open']         ="<li>";
$config['next_tag_close']         ="</li>";
$config['first_tag_open']         ="<li>";
$config['first_tag_close']         ="</li>";
$config['last_tag_open']         ="<li>";
$config['last_tag_close']         ="</li>";


?>