第一步:在浏览器中运行框架,完毕后。在application/index中新建model目录和view目录(view目录里并建index目录)。然后在application里的database.php里配置数据库名 用户名 密码。
第二步:在model目录里新建User.php模型层.
User.php中内容为:
<?php
namespace app\index\model;
use think\Db;//引入Db
use think\Model;//引入Model
class User extends Model
{
protected $table='user';//表名
//增加
function insertData($data)
{
return Db::table($this->table)->insertGetId($data);
}
//查询
function show()
{
return Db::table($this->table)->select();
}
//删除
function deleteData($id)
{
return Db::table($this->table)->where('uid','=',$id)->delete();
}
//查询单条
function findData($id)
{
return Db::table($this->table)->where('uid','=',$id)->find();
}
//修改
function updateData($data,$id)
{
return Db::table($this->table)->where('uid','=',$id)->update($data);
}
}
?>
第三步:controller目录里控制器index.php里面内容为:
<?php
namespace app\index\controller;
use think\controller;//引入控制器
use think\Request;//引入request
use app\index\model\User;//引入模型层
header("content-type:text/html;charset=UTF-8");//防乱码
class Index
{
//表单页面
public function index()
{
//echo 123;
//return '<style type="text/css">*{ padding: 0; margin: 0; } .think_default_text{ padding: 4px 48px;} a{color:#2E5CD5;cursor: pointer;text-decoration: none} a:hover{text-decoration:underline; } body{ background: #fff; font-family: "Century Gothic","Microsoft yahei"; color: #333;font-size:18p