返回模板显示用户信......登陆

模板显示用户信息表,并分页显示

肖凌2019-11-05 23:02:2340

 

//template.php 配置常量 _CSS_

   'tpl_replace_string' =>[     

                                           '_CSS_' =>str_replace('index.php', '', $_SERVER['SCRIPT_NAME'])                                                    ]


//index.php

<?php

        namespace app\index\controller;
        use think\Controller;
        use app\model\User;
        class Index extends Controller{
                    public function index()    {
                              return $this->view->fetch();
                        }
                    public function paginator(){ 

                           //配置title变量    

                             $this->view->assign('user','员工注册信息表');    

                             //配置分页变量    

                             $config=[    'var_page' => 'page'    ];   

                             //每页显示记录数    

                             $num = 5;   

                             //是否为简单分页    

                             $simple = false;    

                             //通过模型__callstatic调用Query类函数paginate    

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

                             //渲染分页    

                                 $page = $paginate->render();    

                             //配置paginate变量    

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

                             //配置page变量    

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

                             //渲染模板   

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

//paginator.html

<!DOCTYPE html>

<html>

         <head>

                     <meta charset="utf-8">

                     <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

                     <link rel="shortcut icon" type="image/x-icon" href="_CSS_static/image/favicon.ico">

                     <link rel="stylesheet" type="text/css" href="_CSS_static/layui/css/layui.css">

                     <script type="text/javascript" src="_CSS_static/layui/layui.js"></script>

                     <style type="text/css">

                                   //分页居中样式

                                .page{width:100%;padding-top:20px; text-align: center;} .pagination{display: inline-block;}

                                 .pagination li{float:left;margin: 0 10px;line-height: 30px;}

                                //当前页面为红色

                                 .active{background: red;height:30px;width:30px;color:#ffffff;}

                      </style>

                     <title>{$user}</title>

             </head>

             <body>

                     <h2 style="text-align:center;margin-top:30px;">{$user}</h2>

                     <table class="layui-table" style="width:60%;margin: 10px auto;text-align: center!important;">   

                            <colgroup>     

                                    <col width="60">    

                                     <col width="50">     

                                     <col width="120">     

                                      <col width="150">  

                            </colgroup>  

                             <thead>     

                                    <tr>       

                                            <th>序号</th>  

                                             <th>ID</th>

                                               <th>用户名</th>

                                               <th>性别</th>

                                               <th>邮箱</th>

                                               <th>密码</th>

                                              <th>描述</th>

                                               <th>工资</th>

                                     </tr> 

                             </thead>  

                             <tbody>

                                     {volist name="ress" id="res"}     

                                                <tr>       

                                                    <td>{$i}</td>      

                                                     <td>{$res.user_id}</td>       

                                                    <td>{$res.username}</td>       

                                                    <td>

                                                               {in name="res.sex" value="0,1"}      

                                                                             {if $res.sex == 0}      

                                                                                         女

                                                                                 {else /}

                                                                                         男      

                                                                             {/if}

                                                               {/in}  

                                                     </td>       

                                                        <td>{$res.email}</td>

                                                        <td>{$res.password}</td>

                                                           <td>{$res.detail}</td>

                                                       <td>{$res.salary}</td>

                                                     </tr>

                                             {/volist}   
                              </tbody>

             </table>

              <div class="page">{$page|raw}</div>
    </body>

</html>

最新手记推荐

• 依赖注入小例子• 模板显示用户信息表,并分页显示• 模板继承,模仿php页面• 模拟用户登录验证的案例 依赖注入 Facade• 创建一个验证器, 用来对模型对应的表中字段进行验证处理

全部回复(0)我要回复

暂无评论~
  • 取消回复发送
  • PHP中文网