Blogger Information
Blog 56
fans 3
comment 1
visits 50793
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
think分页——2018年5月31日
沈斌的博客
Original
863 people have browsed it

thinkPHP分页,view视图中使用 foreach volist 分别实现

application\index\view\staf\demo1.html


实例

{load href="/static/bootstrap/css/bootstrap.css" /}

<div class="container">
    <div class="row">
        <h3 class="text-center">员工信息</h3>
        <div class="col-md-8 col-md-offset-2">
            <table class="table table-bordered table-hover text-center">
                <tr class="info">
                    <td>ID</td>
                    <td>name</td>
                    <td>sex</td>
                    <td>age</td>
                    <td>salary</td>
                </tr>

                {foreach $staffs as $staff}
                <tr>
                    <td>{$staff.staff_id}</td>
                    <td>{$staff.name}</td>
                    <td>{$staff.sex}</td>
                    <td>{$staff.age}</td>
                    <td>{$staff.salary}</td>
                </tr>
                {/foreach}

            </table>

            <div class="text-center">
                {$page | raw}
            </div>
        </div>

    </div>
</div>

{load href="/static/js/jquery-3.3.1.js" /}
{load href="/static/bootstrap/js/bootstrap.js" /}

运行实例 »

点击 "运行实例" 按钮查看在线实例


application\index\view\staf\demo2.html


实例

{load href="/static/bootstrap/css/bootstrap.css" /}

<div class="container">
    <div class="row">
        <h3 class="text-center">员工信息</h3>
        <div class="col-md-8 col-md-offset-2">
            <table class="table table-bordered table-hover text-center">
                <tr class="info">
					<td>ID</td>
					<td>姓名</td>
					<td>性别</td>
					<td>年龄</td>
					<td>工资</td>
				</tr>

                {empty name="staffs"}
                    <h3>没有符合条件的数据</h3>
                {else /}
                {volist name="staffs" id="staff"}
                    <tr>
                        <td>{$staff.staff_id}</td>
                        <td>{$staff.name}</td>
                        <td>
                            {in name="staff.sex" value="0,1"}
                                {if $staff.sex==0}
                                男
                                {else/}
                                女
                                {/if}
                            {/in}
                        </td>
                        <td>
                            {between name="staff.age" value="20,30"}
                            年轻
                            {/between}
                            {between name="staff.age" value="31,50"}
                            中年

                            {/between}

                            {between name="staff.age" value="51,65"}
                            退休
                            {/between}

                        </td>
                        <td>{$staff.salary}</td>
                    </tr>
                {/volist}
                {/empty}
            </table>
            <div class="text-center">
                {$page|raw}
            </div>
        </div>
    </div>
</div>

{load href="/static/js/jquery-3.3.1.js" /}
{load href="/static/bootstrap/js/bootstrap.js" /}

运行实例 »

点击 "运行实例" 按钮查看在线实例

application\index\controller\Staf.php


实例

<?php
    namespace app\index\controller;
    use think\Controller;
    use app\index\model\Staff as StafData;
    use think\facade\Request;

    class Staf extends Controller
    {

        public function query()
        {
            $staff=StafData::get(function($query){
                $query->where('age','>',30)->where('salary','>6000');
            });

            dump($staff);
        }

        // public function softDelete()
        // {
        //     StafData::destroy(11);
        //     $res=StafData::where(11)->select();
        //     dump($res);
        // }

        public function demo1()
        {
            $config=[
                'type'=>'bootstrap',
                'var_page'=>'page'
            ];

            $num=3;
            $simple=false;

            $paginate=StafData::paginate($num,$simple,$config);

            $page=$paginate->render();

            $this->view->assign('staffs',$paginate);

            $this->view->assign('page',$page);

            return $this->view->fetch();
        }

        public function demo2()
        {
            $config=[
                'type'=>'bootstrap',
                'var_page'=>'page'
            ];

            $num=3;
            $simple=false;

            $paginate=StafData::paginate($num,$simple,$config);

            $page=$paginate->render();

            $this->view->assign('staffs',$paginate);

            $this->view->assign('page',$page);

            return $this->view->fetch();
        }
    }

?>

运行实例 »

点击 "运行实例" 按钮查看在线实例

page.png

Correction status:Uncorrected

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post