企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
> 最常用的列表输出, 这里提供一个参考案例, 具体项目可就该对应的dom结构 ## 控制器代码 ``` <?php // 总页数 $view->assign('pagecount', 100); // 模拟用户列表 $data = [ 'title' => 'Hello PHP Angular', 'list' => [ ['id' => 1, 'name' => 'user_1', 'email' => 'email_1@qq.com', 'status' => 1], ['id' => 2, 'name' => 'user_2', 'email' => 'email_2@qq.com', 'status' => 0], ['id' => 3, 'name' => 'user_3', 'email' => 'email_3@qq.com', 'status' => -1], ['id' => 4, 'name' => 'user_4', 'email' => 'email_4@qq.com', 'status' => 1], ['id' => 5, 'name' => 'user_5', 'email' => 'email_5@qq.com', 'status' => 1], ], ]; // 向模板引擎设置数据 $view->assign($data); // 解析显示 $view->display('index'); ``` ## 模板文件 ``` <!DOCTYPE html> <html> <head> <title>列表</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" href="http://apps.bdimg.com/libs/bootstrap/3.3.4/css/bootstrap.css" /> <script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script> <script type="text/javascript" src="http://apps.bdimg.com/libs/bootstrap/3.3.4/js/bootstrap.min.js"></script> </head> <body> <table class="table table-bordered"> <tr> <th>编号</th> <th>用户名</th> <th>邮箱</th> <th>状态</th> <th>操作</th> </tr> <tr php-if="$list" php-repeat="$list as $user"> <td>{$user.id}</td> <td>{$user.name}</td> <td>{$user.email}</td> <td> <php php-switch="$user['status']"> <span php-case="1">正常</span> <span php-case="0">已禁用</span> <span php-case="-1">已删除</span> </php> </td> <td> <a php-show="$user['status'] === 1" php-after="echo ' '" href="javascript:void(0);" class="btn btn-xs btn-warning">禁用</a> <a php-show="$user['status'] === 0" php-after="echo ' '" href="javascript:void(0);" class="btn btn-xs btn-primary">启用</a> <a php-show="$user['status'] >= 0" php-after="echo ' '" href="javascript:void(0);" class="btn btn-xs btn-danger">删除</a> <a php-show="$user['status'] == -1" php-after="echo ' '" href="javascript:void(0);" class="btn btn-xs btn-primary">恢复</a> </td> </tr> <tr php-else=""> <td colspan="3" class="text-center">没有数据</td> </tr> </table> </body> </html> ``` ## 最终效果 ![](https://box.kancloud.cn/2016-05-05_572a316adfe34.png)