ThinkPHP5显示数据库字段内容

1.在application文件夹下面的config.php中打开DEBUG。

2.修改tp5/application/index/controller/Index.php内容。

 1 <?php
 2 namespace appindexcontroller;
 3 //引入系统数据类
 4 use thinkDb;
 5 //引入系统控制器类
 6 use thinkController;
 7 class Index extends Controller
 8 {
 9     public function index()
10     {        
11      //从数据库中读取数据
13 $data=Db::table('user_info')->select(); 14 //var_dump($data); 15 //分配数据给页面 16 $this->assign('data',$data); 17 //加载页面 18 return view(); 19 20 } 21 }

3.修改tp5/application/index/view/index/index.html页面内容。

 1 <!doctype html>
 2 <html>
 3 <head>
 4 <meta charset="utf-8">
 5 <title>无标题文档</title>
 6 </head>
 7 
 8 <body>
 9     <table width="200" border="1">
10       <tbody>
11         <tr>
12           <th>id </th>
13           <th>name </th>
14         </tr>
15           {volist name="data" id="value"}
16               <tr>
17                 <td>{$value.user_id}</td>
18                 <td>{$value.user_name}</td>
19           {/volist}
20       </tbody>
21 </table>
22     <h1>测试一下!</h1>
23 </body>
24 </html>

 4.在http://localhost/tp5/public/下直接查看结果。

原文地址:https://www.cnblogs.com/efyefy/p/8748074.html