abstract:<?phpnamespace 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{ &
<?php
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()
{
//用戶表數(shù)據(jù)
$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();
//查詢數(shù)據(jù)庫當前傳過來的用戶名是否存在
$res = user::where('username',$username)->find();
//如果存在return一個數(shù)組,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管理系統(tǒng),就是操作數(shù)據(jù)庫。繼續(xù)加油。