abstract:
namespace app\admin\controller;
use think\Controller;
use think\facade\Request;
use app\admin\model\User;
use think\facade\Session;
use app\admin\controller\Coomn;
class Userl extends Coomn
{
public function index()
{
//用户表数据
$res = user::all();
$this->assign('res',$res);
return $this->fetch();
}
public function add()
{
return $this->fetch();
}
public function add_do()
{
//接值
$data = Request::param();
//取出username
$username = $data['username'];
$password = $data['password'];
$data['password'] = md5($password);
$data['create_time'] = time();
//查询数据库当前传过来的用户名是否存在
$res = user::where('username',$username)->find();
//如果存在return一个数组,0代表失败,msg提示信息
if (true == $res) {
return ['res'=>0,'msg'=>"用户名已存在"];
}
if (!user::insert($data)) {
return ['res'=>0,'msg'=>"用户添加失败"];
}else{
return ['res'=>1,'msg'=>"用户添加成功"];
}
}
public function dle()
{
$id = Request::param('id');
$data = user::destroy($id);
if ($data ==true) {
return ['res'=>1,'msg'=>'删除成功'];
}else{
return ['res'=>0,'msg'=>'删除失败'];
}
}
public function upl()
{
$id = Request::param('id');
// $res=user::all(function($query)use($id){
// $query->where('id',$id)->find();
// });
$res = user::where('id',$id)->find();
$this->assign('res',$res);
dump($res);
return $this->fetch();
}
public function upl_do()
{
$data = Request::param();
$id = $data['id'];
$res = user::where('id',$id)->update($data);
if (!$res == true) {
return ['res'=>0,'msg'=>'修改失败'];
}else{
return ['res'=>1,'msg'=>'修改成功'];
}
}
}
Correcting teacher:查无此人Correction time:2019-05-17 09:35:43
Teacher's summary:完成的不错,后台cms管理系统,就是操作数据库。继续加油。