
0、开启调试模式(WWW\tp5\application\config.php)
'app_debug' =>true,
1、连接数据库(...database.php)
// 数据库类型
'type' => 'mysql',
// 服务器地址
'hostname' => '127.0.0.1',
// 数据库名
'database' => 'testphp',
// 用户名
'username' => 'root',
// 密码
'password' => 'root',
2、控制器中书写代码(...application\index\controller\Index.php)
<?php
namespace app\index\controller;
//引入系统数据类
use think\Db;
//引入系统控制类
use think\Controller;
class Index extends Controller
{
public function index()
{
//从数据库中读取数据
$data=Db::table('user')->select();
//分配数据给页面
$this->assign('data',$data);
//加载页面
return view();
}
}
3、页面中(...index\view\index\index.html)
{volist name="data" id="value"}
<tr>
<td>{$value.id}</td>
<td>{$value.name}</td>
<td>{$value.pass}</td>
</tr>
{/volist}
人吐槽 | 人点赞 |
发表评论