abstract:
namespace app\admin\controller;
use think\Controller;
use app\admin\model\User;
use think\facade\Session;
use think\facade\Request;
use app\admin\controller\Commn;
use app\admin\model\Newsl;
use app\admin\model\NewslPic;
class NewsPic extends Commn
{
//缩略图展示页面
public function index()
{
//查询新闻标题
$res = NewslPic::order('pic_id','desc')->paginate(4);
$page = $res->render();
$this->assign('res',$res);
$this->assign('page',$page);
return $this->fetch();
}
//文件上传方法
public function upload()
{
//获取文件上传信息
$file = Request::file('file');
//检测文件点后缀//移动到指定文件夹
if ($img = $file->validate(['ext'=>'jpg,png,jpng,gif'])->move('upload')) {
$filename = '/upload/'.$img->getSaveName();
return json(['code'=>1,'msg'=>'上传成功','data'=>$filename]);
}
}
//缩略图添加方法
public function add()
{
$res = Newsl::all();
$this->assign('res',$res);
return $this->fetch();
}
//缩略图添加处理方法
public function add_do()
{
$data = Request::param();
$data['create_time'] = time();
$data['username'] = Session::get('username');
if ($res = NewslPic::insert($data)) {
return json(['code'=>1,'msg'=>'添加缩略图成功']);
}else{
return json(['code'=>2,'msg'=>'添加缩略图失败']);
}
}
//缩略图删除方法
public function del()
{
$data = Request::param();
$pic_id = $data['pic_id'];
if ($res = NewslPic::where('pic_id',$pic_id)->delete()) {
return json(['code'=>1,'msg'=>'删除缩略图成功']);
}else{
return json(['code'=>2,'msg'=>'删除缩略图失败']);
}
}
}
Correcting teacher:查无此人Correction time:2019-06-17 09:31:43
Teacher's summary:完成的不错。一天做了很多作业,对后台管理应该很熟悉了。继续加油。