1
0

RabbitController.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace backend\controllers;
  3. use common\models\RabbitLog;
  4. use Yii;
  5. use yii\web\Controller;
  6. use yii\filters\VerbFilter;
  7. use yii\filters\AccessControl;
  8. use common\models\LoginForm;
  9. use backend\controllers;
  10. use yii\data\ActiveDataProvider;
  11. use common\models\Banner;
  12. /**
  13. * RabbitLog Controller
  14. */
  15. class RabbitController extends Controller
  16. {
  17. /**
  18. * @inheritdoc
  19. */
  20. public function behaviors()
  21. {
  22. return [
  23. 'access' => [
  24. 'class' => AccessControl::className(),
  25. 'rules' => [
  26. [
  27. 'actions' => ['login','view', 'error', 'cjyy'],
  28. 'allow' => true,
  29. ],
  30. [
  31. 'actions' => ['logout', 'index'],
  32. 'allow' => true,
  33. 'roles' => ['@'],
  34. ],
  35. ],
  36. ],
  37. 'verbs' => [
  38. 'class' => VerbFilter::className(),
  39. 'actions' => [
  40. 'logout' => ['post'],
  41. ],
  42. ],
  43. ];
  44. }
  45. public function actionIndex()
  46. {
  47. $dataProvider = new ActiveDataProvider([
  48. 'query' => RabbitLog::find(),
  49. 'sort' => [
  50. 'defaultOrder' => [
  51. 'addtime' => SORT_DESC
  52. ]
  53. ],
  54. ])
  55. ;
  56. return $this->render('index',[
  57. 'dataProvider' => $dataProvider
  58. ]);
  59. }
  60. public function actionView($id){
  61. return $this->render('view',[
  62. 'model'=>RabbitLog::findOne($id),
  63. ]);
  64. }
  65. public function actionCreate()
  66. {
  67. $model = new Banner();
  68. $model->status=Banner::STATUS_DISPLAY;
  69. if ($model->load(Yii::$app->request->post()) && $model->save()) {
  70. //保存操作记录
  71. \common\models\RabbitLog::saveLog('banner','create',$model->searchById($model->primaryKey),$model->primaryKey);
  72. Yii::$app->session->setFlash('success','Banner【'.$model->title.'】发布成功');
  73. return $this->redirect(['index']);
  74. } else {
  75. return $this->render('create', [
  76. 'model' => $model,
  77. ]);
  78. }
  79. }
  80. public function searchById($id){
  81. if (($model = RabbitLog::findOne($id)) !== null) {
  82. return json_encode($model->toArray());
  83. } else {
  84. throw new \yii\web\NotFoundHttpException('The requested page does not exist.');
  85. }
  86. }
  87. }