Ejemplo n.º 1
0
 /**
  * Creates a new BlogPosts model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     BlogAssets::register($this->view);
     FilemanagerTinyAssets::register($this->view);
     $model = new BlogPosts();
     $terms = new BlogTerms();
     $categories = BlogTerms::find()->termType()->orderBy('name')->all();
     if ($model->load(Yii::$app->request->post())) {
         if ($model->validate() && $model->save()) {
             BlogTermRelationships::deleteAll('post_id = ' . $model->id);
             $termRelations = new BlogTermRelationships();
             $categoryTerms = Yii::$app->request->post();
             if (isset($categoryTerms['categories'])) {
                 foreach ($categoryTerms['categories'] as $c) {
                     $termRelations->isNewRecord = true;
                     $termRelations->id = null;
                     $termRelations->post_id = $model->id;
                     $termRelations->term_id = $c;
                     $termRelations->save();
                 }
             }
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             return $this->render('create', ['model' => $model, 'terms' => $terms, 'categories' => $categories]);
         }
     } else {
         return $this->render('create', ['model' => $model, 'terms' => $terms, 'categories' => $categories]);
     }
 }
 /**
  * Creates a new BlogPosts model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new BlogPosts();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }