abstract:<?php/** * Created by PhpStorm. * User: Administrator * Date: 2019/5/27 * Time: 23:41 */namespace app\admin\controller;use app\admin\controller\Common;use think\facade\Request;use think\facade\Sess
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2019/5/27
* Time: 23:41
*/
namespace app\admin\controller;
use app\admin\controller\Common;
use think\facade\Request;
use think\facade\Session;
use app\model\Slide as SlideModel;
class Slide extends Common
{
public function index()
{
$slides = SlideModel::all();
$this->assign('slides',$slides);
//渲染輪播圖管理界面
return $this->fetch();
}
public function add()
{
return $this->fetch();
}
public function upload()
{
//獲取上傳圖片信息
$file = Request::file('file');
//驗證圖片信息并移動到指定目錄
$info = $file->validate(['ext' => 'jpg,jpeg,png,gif'])->move('upload');
if ($info) {
//返回成功的提示信息
return json(['errno'=>0,'data'=>['/upload/'.$info->getSaveName()]]);
} else {
return $file->getError();
}
}
public function doAdd()
{
//獲取提交過來的數據
$data = Request::param();
//加入添加時間
$data['time'] = time();
$data['username'] = Session::get('username');
//把數據添加到數據庫中
$result = SlideModel::create($data);
if ($result) {
return ['res'=>1,'msg'=>'添加成功'];
}else {
return ['res'=>0,'msg'=>'添加失敗'];
}
}
//刪除
public function del()
{
//獲取需要刪除的ID
$slideId = Request::param('id');
$result = SlideModel::destroy($slideId);
if ($result) {
return ['res'=>1,'msg'=>'刪除成功'];
}
}
}
Correcting teacher:天蓬老師Correction time:2019-05-28 17:01:33
Teacher's summary:你有一張圖沒有顯示出來, 是沒有圖, 還是路徑不對.....