CI框架分页(不解错误)
Controller:
function __construct() { parent::__construct(); $this->load->library('page_smart'); $this->load->model('Admin/user_index_data'); $this->load->helper('url'); } //用户列表 function user_list() { $data['user_list']=$this->user_index_data->select_user(); $this->load->view('AdminLogin/user_index/user_list',$data); } //角色列表 function role_list($page) { $config['page']=$page; $config['rows']=1; $config['pagenav']=null; $config['page_size']=$this->user_index_data->select_role_sum(); $page_rst=$this->page_smart->page_do($config); $data['role_list']=$this->user_index_data->select_role($page_rst['select_from'],$page_rst['select_limit']); $data['page_list']=$page_rst['pagenav']; $this->load->view('AdminLogin/user_index/role_list',$data); }
Model:
function __construct() { //装载日期辅助函数 $this->load->helper('date'); //装载数据库函数 $this->load->database(); } /********************* 查询数据部分 **********************/ //查询所有用户数据 function select_user(){ $query=$this->db->query("select id,useranme,password,name,email,mobile_phone,(select role_name from w3a_role where role_id=purview) purview from w3a_user"); return $query->result_array(); } //查询所有的角色数据 function select_role($total,$offset){ $sql="select * from w3a_role limit $total,$offset"; $query=$this->db->query($sql); return $query->result_array(); } function select_role_sum(){ $query=$this->db->get('w3a_role'); return $query->num_rows(); }
分页类:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); class Page_smart{ public function Page_do($config = array()) { if (count($config) > 0) { foreach ($config as $key => $val) { if (isset($this->$key)) { $this->$key = $val; } } } $page=$config['page']; $page_size=$config['page_size']; $pagenav=$config['pagenav']; $rows=$config['rows']; $page_count = ceil($rows/$page_size); if($page <= 1 || $page == '') $page = 1; if($page >= $page_count) $page = $page_count; $select_limit = $page_size; $select_from = ($page - 1) * $page_size; $pre_page = ($page == 1)? 1 : $page - 1; $next_page= ($page == $page_count)? $page_count : $page + 1 ; $pagenav .="<div class='pagination pagination-right'>"; $pagenav .="<ul><li><a href='1'>«</a></li>"; for($i=1;$i<=$page_count;$i++){ if($i==$page) { $pagenav.="<li><a href='$i'>$i</a></li>"; } else { $pagenav.="<li><a href='$i'>$i</a></li>"; } } $pagenav .= "<li><a href='$i'>»</a></li><ul></div>"; $page_result['pagenav']=$pagenav; $page_result['select_limit']=$select_limit; $page_result['select_from']=$select_from; return $page_result; } } /* End of file Someclass.php */ ~
求解释。。。