コード例 #1
0
 /**
  * Creates a new Tag model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Tag();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
コード例 #2
0
ファイル: Article.php プロジェクト: xuguoliangjj/yiiblog
 public function afterSave($insert, $changedAttributes)
 {
     if (!$insert) {
         Tag::deleteAll(['article_id' => $this->id]);
     }
     $tags_arr = explode(',', $this->tags);
     foreach ($tags_arr as $tag) {
         $model = new Tag();
         $model->article_id = $this->id;
         $model->tag = $tag;
         $model->save();
     }
     parent::afterSave($insert, $changedAttributes);
 }