/** * Finds the Tags model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Tags the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Tags::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Tags::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'sort_order' => $this->sort_order, 'created_at' => $this->created_at, 'created_user' => $this->created_user, 'updated_at' => $this->updated_at, 'updated_user' => $this->updated_user]); $query->andFilterWhere(['like', 'label', $this->label])->andFilterWhere(['like', 'status', $this->status]); return $dataProvider; }
public static function matchLabelWithID($labels) { $tagsWithIDs = []; foreach ($labels as $label) { $foundTag = Tags::findOne(['label' => $label]); if (!is_null($foundTag)) { //létezik ilyen cimke $tagsWithIDs[$foundTag->id] = $label; } else { //még nincs ilyen cimke -> mentjük if (trim($label) !== '') { $tag = new Tags(); $tag->label = $label; $tag->status = 'a'; $tag->save(); // már van ID-nk $tagsWithIDs[$tag->id] = $label; } } } return $tagsWithIDs; }
/** * @return \yii\db\ActiveQuery */ public function getTag() { return $this->hasOne(Tags::className(), ['id' => 'tag_id']); }