123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <?php
- namespace backend\controllers;
- use common\models\RabbitLog;
- 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\Banner;
- /**
- * RabbitLog Controller
- */
- class RabbitController extends Controller
- {
- /**
- * @inheritdoc
- */
- public function behaviors()
- {
- return [
- 'access' => [
- 'class' => AccessControl::className(),
- 'rules' => [
- [
- 'actions' => ['login','view', 'error', 'cjyy'],
- 'allow' => true,
- ],
- [
- 'actions' => ['logout', 'index'],
- 'allow' => true,
- 'roles' => ['@'],
- ],
- ],
- ],
- 'verbs' => [
- 'class' => VerbFilter::className(),
- 'actions' => [
- 'logout' => ['post'],
- ],
- ],
- ];
- }
- public function actionIndex()
- {
- $dataProvider = new ActiveDataProvider([
- 'query' => RabbitLog::find(),
- 'sort' => [
- 'defaultOrder' => [
- 'addtime' => SORT_DESC
- ]
- ],
- ])
- ;
- return $this->render('index',[
- 'dataProvider' => $dataProvider
- ]);
- }
- public function actionView($id){
- return $this->render('view',[
- 'model'=>RabbitLog::findOne($id),
- ]);
- }
- public function actionCreate()
- {
- $model = new Banner();
- $model->status=Banner::STATUS_DISPLAY;
- if ($model->load(Yii::$app->request->post()) && $model->save()) {
- //保存操作记录
- \common\models\RabbitLog::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 = RabbitLog::findOne($id)) !== null) {
- return json_encode($model->toArray());
- } else {
- throw new \yii\web\NotFoundHttpException('The requested page does not exist.');
- }
- }
- }
|