1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
- declare (strict_types = 1);
- /**
- * +----------------------------------------------------------------------
- * 后台文章控制制器
- * @author huwhis@163.com
- * @version 0.0.1
- * +----------------------------------------------------------------------
- */
- namespace app\sys\controller;
- // 引入框架内置类
- use think\facade\View;
- use app\common\model\Category as CategoryModel;
- use app\common\model\Article as ArticleModel;
- /**
- * 文章管理
- */
- class Article extends Base
- {
- protected $modelName = "Article";
- public function index()
- {
- $categories = CategoryModel::select();
- $category_tree = list_tree($categories);
-
- $cid = $this->app->request->param('cid');
- $params = $this->app->request->param();
- $list = ArticleModel::queryPage($params);
- View::assign('category_tree', $category_tree);
- View::assign('list', $list);
- View::assign('cid', $cid);
- return View::fetch();
- }
- public function save($id = 0, $cid = 0)
- {
- if ($this->app->request->isPost()) {
- $params = $this->app->request->param();
- if (!$params['cid']) {
- $this->error('请选择栏目');
- }
- if ($params['title'] == '') {
- $this->error("标题不能为空");
- }
- $params['content'] = isset($params['content']) ? $params['content'] : '';
- try {
- if ($params['id'] != 0) {
- ArticleModel::update($params);
- } else {
- $params['userid'] = $this->getSysUser()->userid;
- $params['username'] = $this->getSysUser()->username;
- unset($params['id']);
- ArticleModel::create($params);
- }
- } catch (\Exception $e) {
- $msg = $e->getMessage();
- $this->error("错误提示:".$msg);
- }
- $this->success('操作成功', (string) url('index?cid='.$params['cid']));
- } else {
- if (!$cid) {
- $this->error('请选择栏目');
- }
- if ($id) {
- $data = ArticleModel::find($id);
- } else {
- $data = new ArticleModel();
- }
-
- $category_info = CategoryModel::field('id, parent_id, name')->find($cid);
-
- View::assign('cid', $cid);
- View::assign('category_info', $category_info);
- View::assign('data', $data);
-
- return View::fetch();
- }
- }
- }
|