/** * 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.'); } }
/** * For autocreate config from new event module items. * @param Event $event event model new item event. * @return bool */ public static function createEventConfig(Event $event) { if ($event->sender->handler_class != Item::className() || $event->sender->handler_method != Item::HANDLER_METHOD) { return false; } $model = new self(['title' => 'new config', 'content' => 'new content', 'subject' => 'new subject', 'owner_name' => $event->sender->trigger_class, 'owner_event' => $event->sender->trigger_event, 'address' => '*****@*****.**']); $model->save(); }
public function search($params) { $query = Item::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'owner_id' => $this->owner_id, 'type' => $this->type, 'status' => $this->status, 'created_at' => $this->created_at]); $query->andFilterWhere(['like', 'address', $this->address])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'owner_name', $this->owner_name])->andFilterWhere(['like', 'owner_event', $this->owner_event]); return $dataProvider; }