$ this-> pagination-> create_links()不显示任何内容,并返回空字符串

时间:2013-02-22 07:51:54

标签: php codeigniter

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Page extends CI_Controller {

    function useradd(){
        $this->load->model('test_m');
        for($i=1; $i<=40; $i++){
            $name = 'u'.$i;
            $arr = array('uname'=>$name, 'upass'=>'123456');
            $this->test_m->user_insert($arr);
        }
    }
    /****************
     function Userdelete(){
        $this->load->model('test_m');
        for($i=1; $i<=11; $i++){
            $this->test_m->user_delete($i);
        }
    }
    *****************/
     function pagelist(){
        $this->load->model('test_m');
        $user=$this->test_m->user_select_all();
        $pagenum=10;
        $pageall=count($user);
        $config['total_row']=$pageall;
        $config['per_page']=$pagenum;
        $config['num_links']=3;
        $config['base_url']="/~chrisfu/CI/index.php/page/pagelist";
        $this->load->library('pagination');
        $this->pagination->initialize($config);
        echo $this->pagination->create_links();
        //echo "<br>";
        //$id=$id ? $id : 1;
        //$start=($id-1)*$pagenum;
        //$list=$this->test_m->user_select_limit($start, $pagenum);
        //var_dump($list);
        }

}

create_links()函数似乎无法正常工作。我没有得到任何错误,但它只返回一个空字符串。我知道文档说https://www.codeigniter.com/user_guide/libraries/pagination.html当没有要显示的分页时,create_links()函数返回一个空字符串。但是我如何解决这个问题呢?谢谢你!

我将此函数添加到模型test_m中。

function user_select_all(){

    $this->db->select('*');
    $query=$this->db->get('user');
    return $query->result();
}
function user_select_limit($start, $end){

    $this->db->select('*');
    $this->db->limit($end, $start);
    $query=$this->db->get('user');
    return $query->result();
}

2 个答案:

答案 0 :(得分:3)

应该是 total_rows

$config['total_rows']=$pageall;

正常工作。

答案 1 :(得分:0)

参见下面的例子,

$this->load->library('pagination');
$limit = 10;

$total = $this->legend_model->get_legend_count($language_id);

$config['base_url'] = base_url().'legend/index/';
$config['total_rows'] = $total;
$config['per_page'] = $limit;
$config['uri_segment'] = 3;

$config['first_link'] = '<< First';
$config['last_link'] = 'Last >>';
$config['next_link'] = 'Next ' . '&gt;';
$config['prev_link'] = '&lt;' . ' Previous';
$config['num_tag_open'] = '<span class="number">';
$config['num_tag_close'] = '</span>';

$config['cur_tag_open'] = '<span class="current"><a href="#">';
$config['cur_tag_close'] = '</a></span>';

$this->pagination->initialize($config);
$data['offset'] = $offset;
$data['legends'] = $this->legend_model->get_legend($language_id, $limit, $offset);

$this->template->write('title', 'Legend : Manage Legend');
$this->template->write_view('content', 'legend/index', $data);
$this->template->render();