公益图书馆-UserController-代码学习

1、我的捐书信息

/**
     * @author Edwin
     * @description 显示捐书信息
     */
    public function donate()
    {

        $BookDB = D('Book'); //获取BOOK数据表对象,实例化
        $id = session('user')['id']; //获取当前用户id信息,比如我的id是73

        $where['contributor_id'] = $id; //contributor_id = $id为查询条件

        $count = $BookDB->where($where)->count(); //查询Book数据库id为73的记录,即当前用户记录
        $pager = new Pager($count, "/user/donate", 5); //使用分页栏类来分页显示当前用户已捐书籍
$count表示总的记录数,"/user/donate"为当前网址(控制器及方法),5为每页显示记录数为5
        $limit = $pager->firstItem . ',' . $pager->pageSize; //读取当前页对应的(1,5)第1到第5条(或第6到第10条(6,5))条记录
        $list = $BookDB->where($where)->limit($limit)->select();//把读取出来的当前用户捐赠信息放入$list中


        $this->info_donate=$list; //把读取出来的记录传递给视图页面的info_donate变量

        $this->pager = $pager; //??

        $this->display();
    }

2、我的个人信息

<extend name="Template:template"/>
<block name="title">
    <title>我的个人信息</title>
</block>
<block name="content">

    <table class="table table-striped">
        <caption>我的个人信息</caption>
        <thead>
        <tr>
            <th>用户名</th>
            <th>上次登陆时间</th>
            <th>上次登录ip</th>
            <th>email</th>

        </tr>
        </thead>

        <volist name="info_user" id="vo">
            <tbody>
            <tr>
                <td>{$vo.username}</td>
                <td>{$vo.last_login_time|date='y-m-d H:i',###}</td> //注意时间戳的转换格式
                <td>{$vo.last_login_ip}</td>
                <td>{$vo.email}</td>

            </tr>
            </tbody>
        </volist>
    </table>
    </table>

</block>
</extend>
原文地址:https://www.cnblogs.com/wingjay/p/3900200.html