0
<?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();
}
4

2 回答 2

3

它应该是total_rows

$config['total_rows']=$pageall;

正常工作。

于 2013-02-22T08:28:42.310 回答
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();
于 2013-02-22T09:12:45.283 回答