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