/** * Creates a new News model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new News(); $modelCategory = new NewsCategory(); if (Yii::$app->request->isPost) { foreach (Yii::$app->request->post('NewsTranslation', []) as $language => $data) { foreach ($data as $attribute => $translation) { $model->translate($language)->{$attribute} = $translation; } } } else { $model->status = News::STATUS_ACTIVE; } if ($model->load(Yii::$app->request->post()) && $model->validate()) { $transaction = Yii::$app->db->beginTransaction(); if ($model->save() && $model->saveGallery()) { $transaction->commit(); return $this->redirect(['view', 'id' => $model->id]); } else { $transaction->rollBack(); } } return $this->render('create', ['model' => $model, 'modelCategory' => $modelCategory]); }