摘要:<?php /** * Created by PhpStorm. * User: Administrator * Date: 2019/1/10 * Time: 14:42 */ namespace app\admin\contro
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2019/1/10
* Time: 14:42
*/
namespace app\admin\controller;
use app\admin\controller\Common;
use think\facade\Request;
use app\admin\model\news as NewsModel;
use app\admin\model\newsPic as NewsPicModel;
use think\facade\Session;
class NewsPic extends Common
{
public function index()
{
$newsPic = NewsPicModel::paginate(2);
$this->assign('newsPic',$newsPic);
return $this->fetch();
}
public function add()
{
$news = NewsModel::all();
$this->assign('news',$news);
return $this->fetch();
}
public function DoAdd()
{
$data = Request::param();
$data['add_time'] = time();
$data['username'] = Session::get('username');
$NewsPic = new NewsPicModel();
$res = $NewsPic->save($data);
if($res){
return ['res' => true,'msg' => '上传成功'];
}else{
return ['res' => false,'msg' => '上传失败'];
}
}
public function upload()
{
$file = Request::file('file');
$info = $file->validate(['ext' => 'jpg,jpeg,png,gif'])->move('upload');
if($info){
$fileName = '/upload/'.$info->getSaveName();
return json(['1'=> '上传成功','data' => $fileName]);
}else{
return $info->getError();
}
}
public function del()
{
$delId = Request::param();
// $delNewsPic = NewsPicModel::get($delId);
$res = NewsPicModel::destroy($delId);
if($res){
return ['res' => true,'msg' => '删除成功啦'];
}else{
return ['res' => false,'msg' => '删除失败'];
}
}
}
批改老师:韦小宝批改时间:2019-01-11 13:49:13
老师总结:写的很不错 这个项目写完 自己可以写一个博客站来上线还是很不错的体验哦