1
0

RabbitController.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. public function actionIndex()
  18. {
  19. $dataProvider = new ActiveDataProvider([
  20. 'query' => RabbitLog::find(),
  21. 'sort' => [
  22. 'defaultOrder' => [
  23. 'addtime' => SORT_DESC
  24. ]
  25. ],
  26. ]);
  27. return $this->render('index',[
  28. 'dataProvider' => $dataProvider
  29. ]);
  30. }
  31. public function actionView($id){
  32. return $this->render('view',[
  33. 'model'=>RabbitLog::findOne($id),
  34. ]);
  35. }
  36. public function actionCreate()
  37. {
  38. $model = new Banner();
  39. $model->status=Banner::STATUS_DISPLAY;
  40. if ($model->load(Yii::$app->request->post()) && $model->save()) {
  41. //保存操作记录
  42. \common\models\RabbitLog::saveLog('banner','create',$model->searchById($model->primaryKey),$model->primaryKey);
  43. Yii::$app->session->setFlash('success','Banner【'.$model->title.'】发布成功');
  44. return $this->redirect(['index']);
  45. } else {
  46. return $this->render('create', [
  47. 'model' => $model,
  48. ]);
  49. }
  50. }
  51. public function searchById($id){
  52. if (($model = RabbitLog::findOne($id)) !== null) {
  53. return json_encode($model->toArray());
  54. } else {
  55. throw new \yii\web\NotFoundHttpException('The requested page does not exist.');
  56. }
  57. }
  58. }