/**
  * Creates a new Tag model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     //if(!Yii::$app->user->can('createPost')) throw new HttpException(401, 'No Auth');
     $model = new BlogTag();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Exemple #2
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();
         }
     }
 }