LogController.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace backend\controllers;
  3. use backend\models\search\SystemLogSearch;
  4. use backend\models\SystemLog;
  5. use Yii;
  6. use yii\filters\VerbFilter;
  7. use yii\web\Controller;
  8. use yii\web\NotFoundHttpException;
  9. /**
  10. * LogController implements the CRUD actions for SystemLog model.
  11. */
  12. class LogController extends Controller
  13. {
  14. public function behaviors()
  15. {
  16. return [
  17. 'verbs' => [
  18. 'class' => VerbFilter::className(),
  19. 'actions' => [
  20. 'delete' => ['post'],
  21. 'clear' => ['post'],
  22. ],
  23. ],
  24. ];
  25. }
  26. /**
  27. * Lists all SystemLog models.
  28. * @return mixed
  29. */
  30. public function actionIndex()
  31. {
  32. $searchModel = new SystemLogSearch();
  33. $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
  34. if (strcasecmp(Yii::$app->request->method, 'delete') == 0) {
  35. SystemLog::deleteAll($dataProvider->query->where);
  36. return $this->refresh();
  37. }
  38. $dataProvider->sort = [
  39. 'defaultOrder'=>['log_time'=>SORT_DESC]
  40. ];
  41. return $this->render('index', [
  42. 'searchModel' => $searchModel,
  43. 'dataProvider' => $dataProvider,
  44. ]);
  45. }
  46. /**
  47. * Displays a single SystemLog model.
  48. * @param integer $id
  49. * @return mixed
  50. */
  51. public function actionView($id)
  52. {
  53. return $this->render('view', [
  54. 'model' => $this->findModel($id),
  55. ]);
  56. }
  57. /**
  58. * Deletes an existing SystemLog model.
  59. * If deletion is successful, the browser will be redirected to the 'index' page.
  60. * @param integer $id
  61. * @return mixed
  62. */
  63. public function actionDelete($id)
  64. {
  65. $this->findModel($id)->delete();
  66. return $this->redirect(['index']);
  67. }
  68. /**
  69. * Finds the SystemLog model based on its primary key value.
  70. * If the model is not found, a 404 HTTP exception will be thrown.
  71. * @param integer $id
  72. * @return SystemLog the loaded model
  73. * @throws NotFoundHttpException if the model cannot be found
  74. */
  75. protected function findModel($id)
  76. {
  77. if (($model = SystemLog::findOne($id)) !== null) {
  78. return $model;
  79. } else {
  80. throw new NotFoundHttpException('The requested page does not exist.');
  81. }
  82. }
  83. }