/**
  * 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.');
     }
 }
Beispiel #2
0
 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;
 }