1 Star 0 Fork 0

青苔 / tp-blog

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
Clone or Download
2 2.38 KB
Copy Edit Raw Blame History
lampol authored 2017-11-14 00:00 . 第22个视频
<?php
namespace app\admin\controller;
use app\admin\controller\BaseController;
use think\Request;
use app\admin\model\Category;
use app\admin\model\Article;
class ArticleController extends BaseController
{
/**
* 显示资源列表
*
* @return \think\Response
*/
public function index()
{
$article = new Article;
$articles = $article->getAllArticle(3);
$this->assign('articles',$articles);
return $this->fetch();
}
/**
* 显示创建资源表单页.
*
* @return \think\Response
*/
public function create()
{
$category = new Category;
$cats = $category->getAllCat();
$this->assign('cats',$cats);
return $this->fetch('add');
}
/**
* 保存新建的资源
*
* @param \think\Request $request
* @return \think\Response
*/
public function save(Request $request)
{
$data = $request->except(['file']);
$article = new Article;
$res = $article->addArt($data);
if($res['status']=='fail'){
return $this->error($res['info'],'/admin/article');
}
return $this->success($res['info'],'/admin/article');
}
/**
* 显示指定的资源
*
* @param int $id
* @return \think\Response
*/
public function read($id)
{
//
}
/**
* 显示编辑资源表单页.
*
* @param int $id
* @return \think\Response
*/
public function edit($id)
{
$category = new Category;
$cats = $category->getAllCat();
$this->assign('cats',$cats);
$article = new Article;
$art = $article->getOneArticle($id);
$this->assign('art',$art);
return $this->fetch();
}
/**
* 保存更新的资源
*
* @param \think\Request $request
* @param int $id
* @return \think\Response
*/
public function update(Request $request, $id)
{
$data = $request->except(['_method','file']);
$article = new Article;
$res = $article->updateArticle($data,$id);
if($res['status']=='fail'){
return $this->error($res['info'],'/admin/article');
}
return $this->success($res['info'],'/admin/article');
}
/**
* 删除指定资源
*
* @param int $id
* @return \think\Response
*/
public function delete($id)
{
//
}
}
1
https://gitee.com/adw/tp-blog.git
git@gitee.com:adw/tp-blog.git
adw
tp-blog
tp-blog
master

Search