abstract:
order('id', 'desc')->paginate(6); $this->view->pics = $pics; // 渲染新闻缩略图列表 return $this->fetch(); } public function add() { // 查询所有新闻数据 $news = NewsModel::all(); //将数据赋值给模板 $this->view->news = $news; // 渲染新闻缩略图添加界面 return $this->fetch(); } public function upload() { // 获取上传图片的信息 $file = Request::file('file'); // 验证图片并移动到指定目录 if ($info = $file->validate(['ext' => 'jpg,jpeg,png,gif'])->move('upload')) { // 拼接图片路径 $fileName = '/upload/' . $info->getSaveName(); // 返回上传成功的提示信息 return json([1, '上传成功!', 'data' => $fileName]); } else { // 返回上传失败的错误信息 return $file->getError(); } } public function DoAdd() { // 获取提交的数据 $data = Request::param(); $data['time'] = time(); $data['username'] = Session::get('username'); $newPic = new NewsPicModel(); if ($newPic->save($data)) { return ['res' => 1, 'msg' => '发布成功!']; } else { return ['res' => 0, 'msg' => '发布失败!']; } } public function del() { $picId=Request::param('id'); $newPic = new NewsPicModel(); if ($newPic->destroy($picId)){ return ['res'=>1]; } } }
{include file="/public/head"}