/**
  * Creates a new VidmageTag model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new VidmageTag();
     try {
         if ($model->load($_POST) && $model->save()) {
             return $this->redirect(Url::previous());
         } elseif (!\Yii::$app->request->isPost) {
             $model->load($_GET);
         }
     } catch (\Exception $e) {
         $msg = isset($e->errorInfo[2]) ? $e->errorInfo[2] : $e->getMessage();
         $model->addError('_exception', $msg);
     }
     return $this->render('create', ['model' => $model]);
 }
Ejemplo n.º 2
0
 public function saveManyTags($vidmageTags)
 {
     var_dump($vidmageTags);
     foreach ($vidmageTags as $vidmageTagId) {
         if (!is_numeric($vidmageTagId)) {
             $tag = new Tag();
             $tag->name = $vidmageTagId;
             $tag->save();
             $vidmageTagId = $tag->id;
         }
         $vidmageTag = new VidmageTag();
         $vidmageTag->vidmage_id = $this->id;
         $vidmageTag->tag_id = $vidmageTagId;
         $vidmageTag->save();
     }
 }