一、后台人员管理
1、在后台Action/Admin/下新建一个UserManageAction.class.php
代码:
class UserManageAction extends CommonAction
{
public function index()
{
import('ORG.Util.Page');
$count = M('user')->count();
$page = new Page($count, 10);
$limit = $page->firstRow . ',' . $page->listRows;
$users = M("user")->order('logintime Desc')->limit($limit)->select();
$this->users = $users;
$this->page = $page->show();
$this->display();
}
public function unlock()
{
$id = I('id', '', 'intval');
$re = M('user')->where('id=' . $id)->setField('lock', 0);
if ($re) {
$this->success('修改成功', U('Admin/UserManage/index'));
} else {
$this->error('修改失败');
}
}
public function lock()
{
$id = I('id', '', 'intval');
$re = M('user')->where('id=' . $id)->setField('lock', 1);
if ($re) {
$this->success('修改成功', U('Admin/UserManage/index'));
} else {
echo '没修改';
}
}
}
2、前台Tpl/Admin/新建 UserManage_index.html
显示员工的列表
<foreach name="users" item='v'>
<tr>
<td>{$v.id}</td>
<td>{$v.username}</td>
<td>{$v.password}</td>
<td>{$v.logintime|date='Y--m-d H:i',###}</td>
<td>{$v.loginip}</td>
<td>{$v['lock']?'锁定':'未锁定'}</td>
<td><a href="{:U('Admin/UserManage/unlock',array('id'=>$v['id']))}">解锁</a> <a href="{:U('Admin/UserManage/lock',array('id'=>$v['id']))}">锁定</a></td>
</tr>
</foreach>
注:<foreach>标签是通过thinkphp框架解析的<?php foreach ?>方法
二、使用分页类
1、后台Action中引入page类
代码:
public function index()
{
import('ORG.Util.Page');//引入分页类
$count = M('user')->count();//统计总数
$page = new Page($count, 10);//实例化每页显示10个
$limit = $page->firstRow . ',' . $page->listRows;
$users = M("user")->order('logintime Desc')->limit($limit)->select();
$this->users = $users;
$this->page = $page->show();
$this->display();
}
2、html 展示
<tr>
<td colspan="7" align="center">{$page}</td>
</tr>
代码请看附件: