protected function findModel($id) { if (($model = article_photo::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Updates an existing article model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { /*$model = $this->findModel($id); $photos = new ActiveDataProvider([ 'query' => article_photo::find()-> where(['article_id'=>$id]), ]); if ($model->load(Yii::$app->request->post()) && $model->save()) { $this->uploadphoto(UploadedFile::getInstances($model, 'images'), $model->id); return $this->redirect(['update', 'id' => $model->id]); } else { return $this->render('update', [ 'model' => $model, 'photos' => $photos, ]); }*/ $article = article::find()->where(['id' => $id])->one(); $article_ru = article_ru::find()->where(['article_id' => $id])->one(); $article_en = article_en::find()->where(['article_id' => $id])->one(); $photos = new ActiveDataProvider(['query' => article_photo::find()->where(['article_id' => $id])]); if ($article->load(Yii::$app->request->post()) && $article_ru->load(Yii::$app->request->post()) && $article_en->load(Yii::$app->request->post())) { if ($article->save()) { $this->uploadphoto(UploadedFile::getInstances($article, 'images'), $article->id); $article_ru->save(); $article_en->save(); } return $this->redirect(['update', 'id' => $article->id]); } else { return $this->render('update', ['article' => $article, 'article_ru' => $article_ru, 'article_en' => $article_en, 'photos' => $photos]); } }