更新思路:先展示原信息,再提供修改
//修改之显示
$(document).on('click','.edit',function(){
var id=$(this).parent().parent().children(":first-child").text();
var username=$(this).parent().parent().children(":eq('1')").text();
var password=$(this).parent().parent().children(":eq('2')").text();
var email=$(this).parent().parent().children(":eq('3')").text();
$.get("/lolnews/public/admin/managerlist/edit.html",
{'id':id,'username':username,'password':password,'email':email},
function(data){
$('#ajaxshow').html(data);
})
return false;
});
//修改之提交
$(document).on('click','.submit2',function(){
var id=$('#ccc').text();
var newusername=$('#newusername').val();
var newpassword=$('#newpassword').val();
var newemail=$('#newemail').val();
$.post("/lolnews/public/admin/managerlist/edit.html",
{'id':id,'newusername':newusername,'newpassword':newpassword,'newemail':newemail},
function(data){
$('#ajaxshow').html(data);
})
return false;
});
控制器代码
public function edit(){
if(request()->isPost()){
$id=input('id');
$newusername=input('newusername');
$newpassword=input('newpassword');
$newemail=input('newemail');
$admin=Admin::get($id);
$admin->username=$newusername;
$admin->password=$newpassword;
$admin->email=$newemail;
if($admin->save()){
return '用户更新成功'.'<script>setTimeout("jump1()",1000);</script>';
}else{
return $admin->getError();
}
}
$id=input('id');
$username=input('username');
$password=input('password');
$email=input('email');
return view('edit',['id'=>$id,'username'=>$username,'password'=>$password,'email'=>$email]);
}
至此 管理员功能结束。