/** * Creates a new News model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $models = ['ru' => new Page(), 'en' => new Page(), 'ua' => new Page()]; if (Yii::$app->request->isPost) { //var_dump($_POST); $img = UploadedFile::getInstance($models['ru'], '[ru]image_id'); $img = Image::saveByFile($img); //var_dump($img); if (Page::loadMultiple($models, \Yii::$app->request->post())) { if ($this->alreadyExists($models['ru']->name)) { //TODO: show some error page. cant do via validation it seems return $this->render('create', ['models' => $models]); } $this->adjustModels($models, $img); if (Page::validateMultiple($models)) { foreach ($models as $m) { $m->save(); } return $this->redirect(['view', 'id' => $models['ru']->id]); } else { //var_dump($models['ru']->getErrors()); if ($img !== null) { $img->delete(); } } } } else { return $this->render('create', ['models' => $models]); } }