摘要:<?php namespace app\admin\controller; use app\admin\controller\Common; use app\admin\model\SortModel; use think\facade\Request; use think\facade\Session; class Sor
<?php
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();
$sorts = $sort->order('id','desc')->paginate(3);
$this->view->sorts=$sorts;
return $this->fetch();
}
public function DoAdd()
{
$data = Request::param();
$data['time'] = time();
$data['username'] = Session::get('username');
$sort = new SortModel();
if($sort->save($data))
{
return ['res' => 1,'msg'=>"发布成功"];
}
else
{
return ['res' => 1,'msg'=>"发布失败"];
}
}
public function edit()
{
$sortId = Request::param('id');
$sort = SortModel::get($sortId);
$this->view->sort = $sort;
return $this->fetch();
}
public function DoEdit()
{
$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()
{
$sortId = Request::param('id');
$sort = new SortModel();
if ($sort->destroy($sortId)) {
return ['res'=>1,'msg'=>'删除成功!'];
}
}
}
批改老师:天蓬老师批改时间:2018-12-27 17:06:28
老师总结:$info = $sort->save([
'title' => $data['title'],
'time' => time(),
'username' => Session::get('username'),
], ['id' => $data['id']]);, 将 s