返回分类模块的增删......登陆

分类模块的增删改查操作

意外2019-06-05 13:48:32190
<?php
namespace app\admin\controller;

use app\admin\controller\Common;
use app\admin\model\SortModel;
use think\facade\Request;
use think\facade\Session;

class Sort extends Common
{
   public function index()
   {
       $sort = new SortModel();
       $sorts = $sort->order('id', 'desc')->paginate(8);
       $this->view->sorts = $sorts;
       return $this->fetch();
   }

   public function DoAdd()
   {
       $data = Request::param();
       $data['time'] = time();
       $data['username'] = Session::get('username');
       $sort = new SortModel();
       if ($sort->save($data)) {
           return ['res' => 1, 'msg' => '添加成功!'];
       } else {
           return ['res' => 0, 'msg' => '添加失败!'];
       }
   }

   public function edit()
   {
       $sortId = Request::param('id');
       $sort = SortModel::get($sortId);
       $this->view->sort = $sort;
       return $this->fetch();
   }

   public function DoEdit()
   {
       $data = Request::param();
       $sort = new SortModel();
       $info = $sort->save([
           'title' => $data['title'],
           'time' => time(),
           'username' => Session::get('username'),
       ], ['id' => $data['id']]);
       if ($info) {
           return ['res' => 1, 'msg' => '修改成功!'];
       } else {
           return ['res' => 0, 'msg' => '修改失败!'];
       }
   }

   public function del()
   {
       $sortId = Request::param('id');
       $sort = new SortModel();
       if ($sort->destroy($sortId)) {
           return ['res'=>1,'msg'=>'删除成功!'];
       }

   }
}


最新手记推荐

• 用composer安装thinkphp框架的步骤• 省市区接口说明• 用thinkphp,后台新增栏目• 管理员添加编辑删除• 管理员添加编辑删除

全部回复(0)我要回复

暂无评论~
  • 取消回复发送