Example #1
0
 public static function addTags($tags)
 {
     /*$res = Tag::findAll([
           'name' => $tags,
       ]);
       foreach($res as $tag)
       {
           $tag->updateCounters(['frequency' => 1]);
       }*/
     BlogTag::updateAllCounters(['frequency' => 1], 'name in ("' . implode('"," ', $tags) . '")');
     foreach ($tags as $name) {
         if (!BlogTag::findOne(['name' => $name])) {
             $tag = new BlogTag();
             $tag->name = $name;
             $tag->frequency = 1;
             $tag->save();
         }
     }
 }
Example #2
0
 /**
  * Finds the Tag model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return Tag the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = BlogTag::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }