摘要:<?php
namespace app\admin\controller;
use app\admin\controller\Common;
use app\admin\model\sort as SortModel;
use think\facade\Session;
use think\facade\Request;<?php
namespace app\admin\controller;
use app\admin\controller\Common;
use app\admin\model\sort as SortModel;
use think\facade\Session;
use think\facade\Request;
class Sort extends Common
{
public function index()
{
$sortData = SortModel::order('id','desc')->paginate('6');
$this->assign('sortData',$sortData);
return $this->fetch();
}
public function DoAdd()
{
$sort = Request::param();
$sort['add_time'] = time();
$sort['username'] = Session::get('username');
$sortName = new SortModel;
if($sortName->save($sort)){
return ['res' => 1,'msg' => '添加分类名成功'];
}else{
return ['res' => 0,'msg' => '添加失败'];
}
}
public function edit()
{
$sortId = Request::param();
$SortList = SortModel::field('id,sort_name')->get($sortId);
$this->assign('SortList',$SortList);
return $this->fetch();
}
public function DoEdit()
{
$SortData = Request::param();
// var_dump($SortData);
// exit;
$Sort = SortModel::get($SortData['id']);
$res = $Sort->save([
'sort_name' => $SortData['sort_name']
]);
if($res){
return json(['res' => 1,'msg' => '分类名修改成功']);
}else{
return json(['res' => 0,'msg' => '修改失败']);
}
}
public function del()
{
$id = Request::param();
if($Sort=SortModel::get($id)){
if($Sort->delete()){
return ['res' => 1,'msg' => '删除分类成功'];
}else{
return ['res' => 0,'msg' => '删除失败'];
}
}
return ['res' => 0,'msg' =>'未找到数据,请联系管理员'];
}
}
韦老师,这次提交的是分类了,虽然代码都差不多,不过这次是新鲜的
批改老师:查无此人批改时间:2019-01-11 16:04:08
老师总结:做的不错,之后的作业可以加上你写代码的思路,这样老师可以给你更好的建议,继续加油。