Blogger Information
Blog 28
fans 0
comment 0
visits 16640
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
foreach和volist完成分页-2018年06月03日
植树青年小江同志的博客
Original
687 people have browsed it

controller部分

实例

<?php

namespace app\index\controller;

use think\Controller;
// use think\Request;
use app\index\model\Staff as StaffModel;
use think\facade\Request;

class Staff extends Controller
{
    // foreach 分页查询
    public function foreach()
    {

        $config = [
            'type' => 'bootstrap',
            'var_page' => 'page',
        ];

        $num = 5;

        $simple = false;

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

        $page = $paginate->render();


        // $result = StaffModel::all(function($query) {
        //     $query->field(['staff_id', 'name', 'sex', 'age', 'salary']);
        // });

        // halt($result);

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

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

        return $this->fetch();
    }

    // volist 分页

    public function volist()
    {

        $config = [
            'type' => 'bootstrap',
            'var_page' => 'page',
        ];

        $num = 5;

        $simple = false;

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

        $page = $paginate->render();


        // $result = StaffModel::all(function($query) {
        //     $query->field(['staff_id', 'name', 'sex', 'age', 'salary']);
        // });

        // halt($result);

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

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

        return $this->fetch();
    }
}

运行实例 »

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

foreach

实例

{load href="https://cdn.bootcss.com/bootstrap/4.1.1/css/bootstrap.css" /}

<div class="container">
    <div class="row">
        <div class="col-md-6 com-md-offset-3">

        <h3 class="text-center">表格标签</h3>
            <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 class="danger" >数据为空</h3>
            {else /}
            {foreach $staffs as $staff}

                <tr>
                    <td>{$staff.staff_id}</td>
                    <td>{$staff.name}</td>
                    <td>{$staff.age}</td>
                    <td>
                        {in name="staff.sex" value="0,1"}
                        {if ($staff.sex == 0)}
                            男
                        {else /}
                            女
                        {/if}
                        {/in}
                    </td>
                    <td>{$staff.salary}</td>
                </tr>
            {/foreach}
            {/empty}
            </table>

            <div class="d-flex justify-content-center" aria-label="Page navigation example">{$page|raw}</div>
        </div>
    </div>
</div>

{load href="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js" /}
{load href="https://cdn.bootcss.com/bootstrap/4.1.1/js/bootstrap.min.js" /}

运行实例 »

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

volist

实例

{load href="https://cdn.bootcss.com/bootstrap/4.1.1/css/bootstrap.css" /}

<div class="container">
    <div class="row">
        <div class="col-md-6 com-md-offset-3">

        <h3 class="text-center">表格标签</h3>
            <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 class="danger" >数据为空</h3>
            {else /}
            {volist name="staffs" id="staff"}

                <tr>
                    <td>{$staff.staff_id}</td>
                    <td>{$staff.name}</td>
                    <td>
                        {between name="staff.age" value="20,30"}
                        90后
                        {/between}
                        {between name="staff.age" value="31,50"}
                        中腻男
                        {/between}
                        {between name="staff.age" value="51,9999"}
                        空巢老人
                        {/between}
                        
                    </td>
                    <td>
                        {in name="staff.sex" value="0,1"}
                        {if ($staff.sex == 0)}
                            男
                        {else /}
                            女
                        {/if}
                        {/in}
                    </td>
                    <td>{$staff.salary}</td>
                </tr>
            {/volist}
            {/empty}
            </table>

            <div class="d-flex justify-content-center" aria-label="Page navigation example">{$page|raw}</div>
        </div>
    </div>
</div>

{load href="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js" /}
{load href="https://cdn.bootcss.com/bootstrap/4.1.1/js/bootstrap.min.js" /}

运行实例 »

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


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