亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

管理員的添加,修改,編輯,刪除操作

Original 2019-05-05 22:04:47 690
abstract:<?php namespace app\admin\controller; use think\Controller; use app\admin\model\UserModel; use think\facade\Request; use think\Db; class User extends Control
<?php
namespace app\admin\controller;
use think\Controller;
use app\admin\model\UserModel;
use think\facade\Request;
use think\Db;
class User extends Controller
{
public function index()
{
// 查詢出管理員數(shù)據(jù)
$num = 8;
$type = false;
$config = [
'type' => 'bootstrap',
'var_page' => 'page',
];
// 獲取數(shù)據(jù)
$pagedata = UserModel::order('id','asc')->paginate($num,$type,$config);
// 獲取分頁(yè)
$page = $pagedata->render();
$this->view->assign('user',$pagedata);
$this->view->assign('page',$page);
// 渲染管理員界面
return $this->view->fetch();
}
public function add()
{
// 渲染添加界面
return $this->fetch();
}
public function DoAdd()
{
// request
$data = Request::param();
$data['time'] = time();
$username = $data['username'];
// if
$res = UserModel::where('username','=',$username)->find();
if($res == true){
return ['res' => 0,'msg' => '該用戶名已經(jīng)存在'];
}
// add
$data['password'] = sha1($data['password']);

if(UserModel::insert($data)){
return ['res' => 1,'msg' => '用戶添加成功'];
}else{
return ['res' => 0,'msg' => '用戶添加失敗'];
}
// $user = new userModel();
// if($user->save($data)){
//     return ['res' => '1','msg' => '用戶添加成功'];
// }else{
//     return ['res' => '0','msg' => '用戶添加失敗'];
// }
}
public function edit()  //根據(jù)主鍵Id預(yù)查詢一條數(shù)據(jù)在編輯頁(yè)面上面
{
// 獲取url傳遞Id
$userId = Request::param('id');
// 根據(jù)主鍵Id查詢一條數(shù)據(jù)
$res = UserModel::get($userId);
// 賦值給頁(yè)面
$this->view->assign('urlid',$res);
// 渲染頁(yè)面
return $this->view->fetch();
}
public function DoEdit()  //編輯更新操作
{
// 獲取ajax提交的數(shù)據(jù)
$data = Request::param();
// 執(zhí)行更行操作
$dataId = $data['id'];
$res = UserModel::update([
'username' => $data['username'],
'tel' => $data['tel'],
'email' => $data['email'],
'time' => time(),
],function($query) use ($dataId){
$query->where('id','=',$dataId);
});
// 返回結(jié)果
if($res){
return ['res' => 1,'msg' => '編輯成功!'];
}else{
return ['res' => 0,'msg' => '編輯失敗!'];
}
}
public function del()
{
// 獲取前臺(tái)的主鍵id
$delId = Request::param('id');
// 執(zhí)行刪除
$res = UserModel::where('id','=',$delId)->delete();
// 返回結(jié)果
if($res){
return ['res' => 1,'msg' => '刪除成功!'];
}else{
return ['res' => 0,'msg' => '刪除失敗!'];
}
}
}

ajax異步請(qǐng)求添加

$.ajax({

type: 'post',

url: '{:url(\'User/DoAdd\')}',

dataType: 'json',

data: {

"username": $('#username').val(),

"password": $('#password').val(),

'tel': $('#tel').val(),

'email': $('#email').val(),

},

success: function (data) {

console.log(data);

if (data.res == 1) {

layer.alert(data.msg, {

icon: 6

}, function () {

// 獲得frame索引

var index = parent.layer.getFrameIndex(

window.name);

//關(guān)閉當(dāng)前frame

parent.layer.close(index);

});

} else {

layer.alert(data.msg, {

icon: 6

}, function () {

// 獲得frame索引

var index = parent.layer.getFrameIndex(window.name);

//關(guān)閉當(dāng)前frame

parent.layer.close(index);

});

}

},

})

sdfsf.png

所有的功能測(cè)試完全成功!老師可以看我的github,項(xiàng)目全都push上去了(https://github.com/heyguojing/enterweb)

Correcting teacher:查無此人Correction time:2019-05-06 09:41:51
Teacher's summary:完成的不錯(cuò)。后臺(tái)管理系統(tǒng),最多的操作就是增刪查改數(shù)據(jù)庫(kù)。繼續(xù)加油。

Release Notes

Popular Entries