PHP_THINKPHP_study12_后台人员的管理和分页类的使用

一、后台人员管理

    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>&nbsp;&nbsp;&nbsp;<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>

 代码请看附件:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值