コード例 #1
0
 /**
  * Finds the Item model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Item the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Item::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
コード例 #2
0
ファイル: ItemSearch.php プロジェクト: bariew/yii2-log-module
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @param null $fullName
  * @return ActiveDataProvider
  */
 public function search($params, $fullName = null)
 {
     $query = Item::find();
     // add conditions that should always apply here
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['created_at' => SORT_DESC]]]);
     $this->load($params, $fullName);
     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;
     }
     // grid filtering conditions
     $query->andFilterWhere(['id' => $this->id, 'user_id' => $this->user_id]);
     $query->andFilterWhere(['like', 'event', $this->event])->andFilterWhere(['like', 'model_name', $this->model_name])->andFilterWhere(['like', 'model_id', $this->model_id])->andFilterWhere(['like', 'message', $this->message]);
     if ($this->created_at) {
         $query->andWhere("DATE_FORMAT(FROM_UNIXTIME(created_at), '%Y-%m-%d') = :created_at")->addParams([':created_at' => $this->created_at]);
     }
     return $dataProvider;
 }
コード例 #3
0
 public static function common(Event $event)
 {
     return Item::create($event)->save(false);
 }