Fetch the repository succeeded.
<?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)
{
//
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。