123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- <?php
- namespace backend\controllers;
- use Yii;
- use yii\web\Controller;
- use yii\filters\VerbFilter;
- use yii\filters\AccessControl;
- use common\models\LoginForm;
- use backend\controllers;
- use yii\data\ActiveDataProvider;
- use common\models\AdminLog;
- use common\models\Banner;
- /**
- * AdminLog Controller
- */
- class AdminController extends Controller
- {
- public function actionIndex()
- {
- $dataProvider = new ActiveDataProvider([
- 'query' => AdminLog::find(),
- 'sort' => [
- 'defaultOrder' => [
- 'addtime' => SORT_DESC
- ]
- ],
- ]);
- return $this->render('index',[
- 'dataProvider' => $dataProvider
- ]);
- }
- public function actionView($id){
- return $this->render('view',[
- 'model'=>AdminLog::findOne($id),
- ]);
- }
- public function actionCreate()
- {
- $model = new Banner();
- $model->status=Banner::STATUS_DISPLAY;
- if ($model->load(Yii::$app->request->post()) && $model->save()) {
- //保存操作记录
- \common\models\AdminLog::saveLog('banner','create',$model->searchById($model->primaryKey),$model->primaryKey);
- Yii::$app->session->setFlash('success','Banner【'.$model->title.'】发布成功');
- return $this->redirect(['index']);
- } else {
- return $this->render('create', [
- 'model' => $model,
- ]);
- }
- }
- public function searchById($id){
- if (($model = Banner::findOne($id)) !== null) {
- return json_encode($model->toArray());
- } else {
- throw new \yii\web\NotFoundHttpException('The requested page does not exist.');
- }
- }
- }
|