/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = UserLog::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'object_pk' => $this->object_pk, 'created_at' => $this->created_at, 'is_success' => $this->is_success]); $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'action', $this->action])->andFilterWhere(['like', 'object_class', $this->object_class]); return $dataProvider; }
/** * Lists all UserLog models. * @return mixed */ public function actionIndex($action = '') { if (!$this->is_access('userlog/index')) { Yii::$app->session->setFlash('error', $this->errorInfo); return $this->redirect($this->redirectUrl); } $query = UserLog::find(); if ($action) { $query = $query->andWhere(['action' => $action]); } if (isset($_GET['UserLog'])) { $first_time = $_GET['UserLog']['first_time']; $first_time = empty($first_time) ? 0 : strtotime($first_time); $last_time = $_GET['UserLog']['last_time']; $last_time = empty($last_time) ? 2446647875 : strtotime($last_time) + 86400; $query->andWhere(['between', 'add_time', $first_time, $last_time]); } $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]); Yii::$app->view->params['meta_title'] = '后台操作日志'; return $this->render('index', ['dataProvider' => $dataProvider, 'model' => new UserLog()]); }