Ejemplo n.º 1
0
 /**
  * Creates a new ArticleCategory model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new ArticleCategory();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 /**
  * Creates a new ArticleCategory model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new ArticleCategory();
     $categories = ArticleCategory::find()->noParents()->all();
     $categories = ArrayHelper::map($categories, 'id', 'title');
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['index']);
     } else {
         return $this->render('create', ['model' => $model, 'categories' => $categories]);
     }
 }
Ejemplo n.º 3
0
 /**
  * Save Article model
  * @param bool $insert
  */
 public function saveArticle($insert = true)
 {
     $article = $insert === true ? new Article() : Article::findOne($this->item_id);
     $imageId = null;
     if (!isset(Yii::$app->request->post('ArticleForm')['imageFilename'])) {
         $this->imageFilename = null;
     }
     if ($this->imageFilename) {
         $imageId = Image::find()->andWhere(['filename' => $this->getImageName()])->scalar();
     }
     $this->image_id = $imageId;
     $article->attributes = $this->toArray();
     if ($this->content_date) {
         $article->content_date = Yii::$app->formatter->asDate($this->content_date, 'y-MM-dd');
     }
     if ($this->content_end_date) {
         $article->content_end_date = Yii::$app->formatter->asDate($this->content_end_date, 'y-MM-dd');
     }
     if ($this->content_time) {
         $article->content_time = Yii::$app->formatter->asTime($this->content_time, 'HH:mm');
     }
     $article->active = is_array($this->boxes) && in_array(self::PROPERTY_ACTIVE, $this->boxes) ? 1 : 0;
     $article->public = is_array($this->boxes) && in_array(self::PROPERTY_PUBLIC, $this->boxes) ? 1 : 0;
     if ($this->item_id) {
         ArticleCategory::deleteAll(['article_id' => $this->item_id]);
     }
     $article->tagValues = $this->tagValues;
     $article->save(false);
     if (is_array($this->categoryBoxes)) {
         foreach ($this->categoryBoxes as $categoryBox) {
             $articleCategory = new ArticleCategory();
             $articleCategory->article_id = $article->id;
             $articleCategory->category_id = $categoryBox;
             $articleCategory->save();
         }
     }
 }