/** * Updates an existing lab model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $lab = lab::find()->where(['id' => $id])->one(); $lab_ru = lab_ru::find()->where(['lab_id' => $id])->one(); $lab_en = lab_en::find()->where(['lab_id' => $id])->one(); if (!empty(UploadedFile::getInstances($lab, 'images'))) { if ($lab->load(Yii::$app->request->post())) { if (file_exists($path = getcwd() . '\\..\\..' . $lab->photo_path)) { unlink($path); } if (file_exists($path = getcwd() . '\\..\\..' . $lab->photo_path427320)) { unlink($path); } $images = UploadedFile::getInstances($lab, 'images'); $newFileName = date("YmdHis"); $filePath = Yii::getAlias('@frontend') . '/web/uploads/' . $newFileName . '.' . $images[0]->extension; $file427320 = Yii::getAlias('@frontend') . '/web/uploads/427320/' . $newFileName . '.' . $images[0]->extension; $images[0]->saveAs($filePath); Image::thumbnail($filePath, 427, 320)->save($file427320, ['quality' => 50]); $lab->photo_path = Yii::getAlias('@resource') . '/uploads/' . $newFileName . '.' . $images[0]->extension; $lab->photo_path427320 = Yii::getAlias('@resource') . '/uploads/427320/' . $newFileName . '.' . $images[0]->extension; } } if ($lab->load(Yii::$app->request->post()) && $lab_ru->load(Yii::$app->request->post()) && $lab_en->load(Yii::$app->request->post()) && $lab->save()) { $lab_ru->save(); $lab_en->save(); return $this->redirect(['update', 'id' => $lab->id]); } else { return $this->render('update', ['lab' => $lab, 'lab_ru' => $lab_ru, 'lab_en' => $lab_en]); } }
public function actionView($id) { $lab = lab::find()->where(['id' => $id])->one(); return $this->render('view', ['lab' => $lab]); }