/**
  * Creates a new MArticleMultArticle model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate($article_mult_id)
 {
     $articleMult = MArticleMult::findOne($article_mult_id);
     $model = new MArticleMultArticle();
     $model->article_mult_id = $article_mult_id;
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         //            return $this->redirect(['view', 'id' => $model->article_mult_article_id]);
         return $this->redirect(['index', 'article_mult_id' => $model->article_mult_id]);
     } else {
         return $this->render('create', ['model' => $model, 'articleMult' => $articleMult]);
     }
 }
Example #2
0
 public function afterSave($insert, $changedAttributes)
 {
     parent::afterSave($insert, $changedAttributes);
     $this->articleIds = explode(',', $this->articleIdsStr);
     $deleteArticleIds = array_diff($this->_oldArticleIds, $this->articleIds);
     $addArticleIds = array_diff($this->articleIds, $this->_oldArticleIds);
     foreach ($this->articleMultArticles as $articleMultArticle) {
         if (in_array($articleMultArticle->article_id, $deleteArticleIds)) {
             $articleMultArticle->delete();
         }
     }
     foreach ($addArticleIds as $articleId) {
         $model = new MArticleMultArticle();
         $model->article_mult_id = $this->article_mult_id;
         $model->article_id = $articleId;
         $model->save(false);
     }
 }