1
0

AdminController.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace backend\controllers;
  3. use Yii;
  4. use yii\web\Controller;
  5. use yii\filters\VerbFilter;
  6. use yii\filters\AccessControl;
  7. use common\models\LoginForm;
  8. use backend\controllers;
  9. use yii\data\ActiveDataProvider;
  10. use common\models\AdminLog;
  11. use common\models\Banner;
  12. /**
  13. * AdminLog Controller
  14. */
  15. class AdminController extends Controller
  16. {
  17. public function actionIndex()
  18. {
  19. $dataProvider = new ActiveDataProvider([
  20. 'query' => AdminLog::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'=>AdminLog::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\AdminLog::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 = Banner::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. }