Blogger Information
Blog 8
fans 0
comment 0
visits 5796
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
使用foreach和volist标签分别实现模板数据的分页显示-2018年5月30日
往昔流逝的博客
Original
594 people have browsed it

1.控制器代码Users:

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

class Users extends Controller{

   public function pagelist(){
       $config = ['type'=>'bootstrap','var_page'=>'page'];
       $num = 5;
       $simple = false;
       $list = UsersModel::paginate($num, $simple, $config);
       $page = $list->render();

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

2.view视图代码Users/pagelist:

<!DOCTYPE html>
<html lang="en">
<head>
   <meta charset="UTF-8">
   <title>数据分页</title>
</head>
<body>
   <div class="col-md-8">
       <table class="table text-center table-hover">
           <tr class="info">
               <td>ID</td>
               <td>用户名</td>
               <td>性别</td>
           </tr>
           {foreach name="list" item="val"}
           <tr>
               <td>{$val.id}</td>
               <td>{$val.name}</td>
               <td>{//$val.sex}
                   {in name="$val.sex" value="0,1"}
                       {if $val.sex == 0}男
                       {else /}女
                       {/if}
                   {/in}
               </td>
           </tr>
           {/foreach}

           {//volist name="list" item="val"}
           <tr>
               <td>{$val.id}</td>
               <td>{$val.name}</td>
               <td>{//$val.sex}
                   {in name="$val.sex" value="0,1"}
                   {if $val.sex == 0}男
                   {else /}女
                   {/if}
                   {/in}
               </td>
           </tr>
           {///volist}
       </table>
       {$page|raw}
   </div>
</body>
</html>

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!