C
<?php
/**
*用户操作类.
*/
defined('BASEPATH') or exit('No direct script access allowed');
class Mail extends MY_AdminController
{
public function __construct()
{
parent::__construct();
//判断管理员权限
$this->adminverify();
//连接数据库
$this->Switchdatabase();
//引入模型
$this->load->model('admin/mail_model', 'adminmail');
}
public function list()
{
$list = $this->adminmail->list();
//载入分页类
$this->load->library('pagination');
$this->load->helper('url');
$perPage = 10; //每页10条
//配置项设置
$config['base_url'] = site_url().'admin/mail/list';
$config['total_rows'] = $this->db->count_all_results('mail');
$config['per_page'] = $perPage;
$config['uri_segment'] = 3; //偏移量,默认是3,如果在控制器有二级目录,根据偏移量层级而定
//自定义配置
$config['first_link'] = '首页';
$config['prev_link'] = '上一页';
$config['next_link'] = '下一页';
$config['last_link'] = '尾页';
//传入配置项,并生成链接
$config['page_query_string'] = true;
$config['reuse_query_string'] = true;
$this->pagination->initialize($config);
//设置偏移量
$page = (int) $this->uri->segment(3); // 获取页码
$p = (int) $this->input->get('per_page');
$p = ($p + 10) / 10;
$offset = $p == false ? 0 : ($config['per_page'] * ($p - 1));
$this->db->limit($perPage, $offset);
//加载模型类和视图
$data['list'] = $this->adminmail->list();
$data['links'] = $this->pagination->create_links();
$this->load->view('form', $data);
//jsonExit(100, 'success', $list);
}
M
<?php
class Mail_model extends CI_Model
{
public function __construct()
{
parent::__construct();
// Your own constructor code
}
public function list()
{
$list = $this->db->get('mail')->result_array();
return $list;
}
V
<table>
<tr>
<td>ID</td>
</tr>
<?php foreach ($list as $v):?>
<tr>
<td><?php echo $v['id']; ?></td>
</tr>
<?php endforeach; ?>
</table>
<?php echo $links; ?>
结果