博主信息
博文 46
粉丝 3
评论 1
访问量 40831
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
5.30 模板标签、分页与上传
吃不起土的少年的博客
原创
906人浏览过

实例

控制器代码

<?php
namespace app\index\Controller;
use think\Controller;
use app\index\model\StaffList as StaffTest;

class Stafflist extends Controller
{
  public function example()
  {
    $staff =StaffTest::all (function($query){
      $query->field(['staff_id','name','sex','age','salary']);
    });

     // dump($staff);exit;

     $this->view->assign('staff',$staff);
     return $this->view->fetch();
  }

  public function example2()
  {

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

    $num =5;

    $simple =false;
    $paginate= StaffTest::paginate($num,$simple,$config);
    $page = $paginate->render();

    $this->view->assign('staff',$paginate);
    $this->view->assign('page',$page);
    return $this->view->fetch('example');

  }
}
 ?>

运行实例 »

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

用foreach分页显示

实例

{load href="/static/bootstrap/css/bootstrap.css"}
<div class="container">
  <div class="row">
    <h2 class="text-center">员工信息表</h2>
    <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>

                {//assign name="staff" value=":\app\index\model\StaffList::all()" /}
                {foreach $staff as $staffs}
                <tr>
                  <td>{$staffs.staff_id}</td>
                  <td>{$staffs.name}</td>
                  <td>{$staffs.sex}</td>
                  <td>{$staffs.age}</td>
                  <td>{$staffs.salary}</td>
                </tr>
                {/foreach}
       
      </table>
      <div class="text-center">{$page|raw}</div>
    </div>
  </div>
</div>
{load href="/static/jQuery/jquery-3.3.1.js" /}
{load href="/static/bootstrap/js/bootstrap.js" /}

运行实例 »

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

QQ截图20180603111334.png

用volist分页

实例

{load href="/static/bootstrap/css/bootstrap.css"}
<div class="container">
  <div class="row">
    <h2 class="text-center">员工信息表</h2>
    <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>      
        {volist name="staff" id="staffs"}
        {//eq name="mod" value="0"}
        <tr>
          <td>{$staffs.staff_id}</td>
          <td>{$staffs.name}</td>
          <td>{//$staffs.sex}
               {in name="staffs.sex" value="0,1" }
               {if $staffs.sex==0}
               男
               {else }
               女
               {/if}
               {/in}
          </td>
          <td>{$staffs.age}</td>
          <td>{$staffs.salary}</td>
          {///eq}
        </tr>
        {/volist}
      </table>
      <div class="text-center">{$page|raw}</div>
    </div>
  </div>
</div>
{load href="/static/jQuery/jquery-3.3.1.js" /}
{load href="/static/bootstrap/js/bootstrap.js" /}

运行实例 »

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

QQ截图20180603111443.png

批改状态:合格

老师批语:
本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
作者最新博文
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学