abstrak:<?php/** * Created by PhpStorm. * User: Administrator * Date: 2019-02-19 * Time: 17:40 */namespace app\admin\controller;use app\admin\controller\Common;use app\admin\model\SortModel;use think\facad
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2019-02-19
* Time: 17:40
*/
namespace app\admin\controller;
use app\admin\controller\Common;
use app\admin\model\SortModel;
use think\facade\Request;
use think\facade\Session;
class Sort extends Common
{
public function index()
{
//實例化模型
$sort = new SortModel();
//查詢數(shù)據(jù)
$sorts = $sort->order('id','desc')->paginate(8);
//模板賦值
$this->view->sorts=$sorts;
//渲染列表模板
return $this->fetch();
}
public function DoAdd()
{
//獲取提交過來的數(shù)據(jù)
$data = Request::param();
//添加時間
$data['time'] = time();
//獲取發(fā)布管理員
$data['username'] = Session::get('username');
//實例化
$sort = new SortModel();
//存儲驗證
if($sort->save($data)){
//返回信息
return ['res'=>1,'msg'=>'添加成功!'];
}else{
return ['res'=>0,'msg'=>'添加是不!'];
}
}
public function edit()
{
//獲取需要修改的分類id
$sortId =Request::param('id');
//使用分類的id查詢對應的數(shù)據(jù)
$sort = SortModel::get($sortId);
//將數(shù)據(jù)賦值給模板
$this->view->sort = $sort;
//渲染修改界面
return $this->fetch();
}
public function DoEdit()
{
//獲取提交數(shù)據(jù)
$data = Request::param();
//實例化模型
$sort = new SortModel();
//更新操作
$info = $sort->save([
'title'=> $data['title'],
'time' =>time(),
'username'=>Session::get('username')
],['id'=>$data['id']]);
//判斷
if($info){
return ['res'=>1,'msg'=>'修改成功!'];
}else{
return ['res'=>0,'msg'=>'修改失敗!'];
}
}
public function del()
{
//獲取需要刪除的id
$sortId =Request::param('id');
//實例化模型
$sort = new SortModel();
//刪除并驗證
if($sort->destroy($sortId)){
return ['res'=>1,'msg'=>'刪除成功!'];
}
}
}
Guru membetulkan:查無此人Masa pembetulan:2019-02-20 09:04:21
Rumusan guru:完成的不錯,后臺管理最主要的就是數(shù)據(jù)庫的增刪查改,多練習對你幫助很大,繼續(xù)加油。