摘要:<?phpnamespace app\admin\controller;//use think\facade\View; //view創(chuàng)建靜態(tài)代理use app\admin\model\SortModel;use think\Controller;use app\admin\controller\Common;//訪問入口use think\facade\Request;//系統(tǒng)
<?php
namespace app\admin\controller;
//use think\facade\View; //view創(chuàng)建靜態(tài)代理
use app\admin\model\SortModel;
use think\Controller;
use app\admin\controller\Common;//訪問入口
use think\facade\Request;//系統(tǒng)控制器
use think\facade\Session;//系統(tǒng)緩存
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()
{
//獲取提交過來的數(shù)據(jù)
$data = Request::param();
//獲取添加時間
$data['time'] = time();
//獲取添加管理員
$data['username'] = Session::get('username');
//實例化模型
$sort = new SortModel();
//添加到數(shù)據(jù)庫中
if($sort->save($data)){
return['res'=>1,'msg'=>'添加成功!'];
}else{
return['res'=>0,'msg'=>'添加失?。?#39;];
}
//渲染管理員添加界面
return $this->fetch();
}
public function edit()
{
//獲取提交過來的信息
$sortId = Request::param('id');
//使用分類的id查詢對應(yīng)的數(shù)據(jù)
$sort = SortModel::get($sortId);
//將數(shù)據(jù)賦值給模板
$this->view->sort = $sort;
//渲染管理員編輯界面
return $this->fetch();
}
public function DoEdit()
{
//獲取提交過來的數(shù)據(jù)
$data = Request::param();
//實例化模型
$sort = new SortModel();
//更新內(nèi)容
$info = $sort->save([
'title' => $data['title'],
'username' => Session::get('username'),
'time' => time(),
],['id'=>$data['id']]);
if($info){
return['res'=>1, 'msg'=>'修改成功!'];
}else{
return['res'=>0, 'msg'=>'修改失敗!'];
}
}
public function del()
{
//獲取傳入的id
$sortId = Request::param('id');
//實例化模型
$sort = new SortModel();
//
if($sort->destroy($sortId )){
return['res'=>1,'msg'=>'刪除成功!'];
}
}
}
批改老師:查無此人批改時間:2019-06-20 09:48:54
老師總結(jié):完成的不錯。熟悉了框架,常規(guī)操作對你來說就很簡單了。繼續(xù)加油。