摘要:<?phpnamespace 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\
<?php
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
{
//縮略圖展示頁(yè)面
public function index()
{
//查詢新聞標(biāo)題
$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');
//檢測(cè)文件點(diǎn)后綴//移動(dòng)到指定文件夾
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'=>'刪除縮略圖失敗']);
}
}
}
批改老師:查無(wú)此人批改時(shí)間:2019-06-17 09:31:43
老師總結(jié):完成的不錯(cuò)。一天做了很多作業(yè),對(duì)后臺(tái)管理應(yīng)該很熟悉了。繼續(xù)加油。