1

我目前正在使用codeigniter + twitter bootstrap进行一个项目,我试图在其中实现分页,但是当我在视图页面中回显链接时它什么都不显示,我已经粘贴了下面的代码,我也在我以前的项目中使用了这个代码也有它工作正常,但现在不是,我无法弄清楚这个问题,我希望有人给我一个建议。
这是我的索引函数,

    $this->load->helper('url'); 
    $this->load->model('albums');
    $this->load->library('pagination');

    $config = array();
    $config["base_url"] = base_url() . "admin/gallery";
    $config["total_albums"] = $this->albums->all_albums_count();
    $config["per_page"] = 2;
    $config['num_links'] = 5;
    $config["uri_segment"] = 3;


    $config['full_tag_open'] = '<div class="pagination"><ul>';
    $config['full_tag_close'] = '</ul></div><!--pagination-->';
    $config['first_link'] = '&laquo; First';
    $config['first_tag_open'] = '<li class="prev page">';
    $config['first_tag_close'] = '</li>';

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

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

    $config['prev_link'] = '&larr; 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);

    $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
    $data['query'] = $this->albums->get_all_albums($config["per_page"], $page);


    $data['links'] = $this->pagination->create_links();

    $data['albumcount'] = $config["total_albums"];
    var_dump($data['links']);
    var_dump($config);
    $this->load->view('layouts/admin_header');
    $this->load->view('admin/gallery_view', $data);
    $this->load->view('layouts/admin_footer');

在我的视图文件中,我使用了

 <?php echo $links; ?>

但它什么也没显示,所以我在控制器中使用 var_dump() 来知道结果,

var_dump($data['links']);

它给: string(0) ""

var_dump($config);

它给 :

array(23) { ["base_url"]=> string(41) "http://localhost/sch_manage/admin/gallery" ["total_albums"]=> int(3) ["per_page"]=> int(2) ["num_links"]=> int(5) ["uri_segment"]=> int(3) ["full_tag_open"]=> string(28) "
    " ["full_tag_close"]=> string(28) "
    " ["first_link"]=> string(13) "« First" ["first_tag_open"]=> string(22) "
    " ["first_tag_close"]=> string(5) "
    " ["last_link"]=> string(12) "Last »" ["last_tag_open"]=> string(22) "
    " ["last_tag_close"]=> string(5) "
    " ["next_link"]=> string(11) "Next →" ["next_tag_open"]=> string(22) "
    " ["next_tag_close"]=> string(5) "
    " ["prev_link"]=> string(15) "← Previous" ["prev_tag_open"]=> string(22) "
    " ["prev_tag_close"]=> string(5) "
    " ["cur_tag_open"]=> string(30) "
    " ["cur_tag_close"]=> string(9) "
    " ["num_tag_open"]=> string(17) "
    " ["num_tag_close"]=> string(5) "
    " }

在我的视图页面中,我使用<?php echo $albumcount; ?>它正确显示专辑总数。和专辑限制也可以正常工作$config["per_page"] = 2; ,但当我回显分页链接时,它们没有显示。

4

2 回答 2

5

您正在通过每张专辑计数,total_albums分页库正在寻找total_rows

于 2013-04-22T07:49:51.630 回答
0
$this->load->model('reciever');
                $this->load->library('uri');
                $this->load->library('pagination');
                $config['base_url'] = base_url(). 'users_ci/users';
                $config['total_rows'] = $this->reciever->getRows();
                $config['per_page'] = 4;
                $config['full_tag_open'] = '<ul class="pagination">';
                $config['full_tag_close'] = '</ul>';            
                $config['prev_link'] = '&laquo;';
                $config['prev_tag_open'] = '<li>';
                $config['prev_tag_close'] = '</li>';
                $config['next_link'] = '&raquo;';
                $config['next_tag_open'] = '<li>';
                $config['next_tag_close'] = '</li>';
                $config['cur_tag_open'] = '<li class="active"><a href="#">';
                $config['cur_tag_close'] = '</a></li>';
                $config['num_tag_open'] = '<li>';
                $config['num_tag_close'] = '</li>';
                $config["num_links"] = round( $config["total_rows"] / $config["per_page"] );
                $config['users']= $this->reciever->getUsers(4,$this->uri->segment(3));
                $this->pagination->initialize($config);
                $config['pages'] = $this->pagination->create_links();
                $this->load->view('users',$config);

对于你正在做的视图

<div><?php echo $pages; ?></div>
于 2013-10-22T10:05:20.807 回答