Доброго времени суток,.. У меня есть сайт решил добавить туда блог .- сейчас нужно реализовать функционал загрузки картинок и отображения их в статьи ,но у меня уже существует такая функция но ,- для заполнения профиля . И эту функцию можно использовать не только для блога но и в любом месте скрипта . Как сделать пере направление ,-чтоб всё работало. вот модель и контроллер / Код (Text): public function uploadAvatar($filePath) { $file = UploadedFile::getInstance($this, 'avatar'); // if no file was uploaded abort the upload if ( null === $file ) { return false; } // file extension $fileExt = $file->extension; // purge filename $fileName = \Yii::$app->security->generateRandomString(); // update file->name $file->name = $fileName.".{$fileExt}"; // update avatar field $this->avatar = $fileName.".{$fileExt}"; // save images to imagePath $file->saveAs($filePath.$fileName.".{$fileExt}"); return $file; } /** * fetch stored image file name with complete path * * @return string * @throws InvalidParamException */ public function getImagePath() { return $this->avatar ? \Yii::getAlias(\Yii::$app->getModule('userextended')->avatarPath).$this->avatar : null; } /** * fetch stored image url * * @return string * @throws InvalidParamException */ public function getImageUrl() { if ( !$this->avatar && $this->getAccountAttributes() !== null ) { $imageURL = $this->getSocialImage(); } else { $avatar = $this->avatar ?: 'default.png'; $imageURL = \Yii::getAlias(\Yii::$app->getModule('userextended')->avatarURL).$avatar; } return $imageURL; } /** * Process deletion of image * * @param string $avatarOld * * @return bool * @throws InvalidParamException */ public function deleteImage($avatarOld) { $avatarURL = \Yii::getAlias(\Yii::$app->getModule('userextended')->avatarPath).$avatarOld; // check if file exists on server if (empty($avatarURL) || !file_exists($avatarURL)) { return false; } // check if uploaded file can be deleted on server if (!unlink($avatarURL)) { return false; } // if deletion successful, reset your file attributes $this->avatar = null; return true; } /** * Get image form Social * * @return string */ public function getSocialImage() { $account = $this->getAccountAttributes(); switch($account['provider']) { case 'facebook': /** @var Account $account */ $imageURL = 'https://graph.facebook.com/' . $account['client_id'] . '/picture?type=large'; break; case 'twitter': /** @var Account $account */ $imageURL = ''; break; default: $imageURL = null; } return $imageURL; } Код (Text): public function actionProfile() { // Load Model $model = $this->finder->findProfileById( Yii::$app->user->identity->getId() ); // If Profile not exist create it if ($model === null) { $model = Yii::createObject(Profile::class); $model->link('user', Yii::$app->user->identity); } // Load Old Image $oldImage = $model->avatar; // Load avatarPath from Module Params $avatarPath = Yii::getAlias( Yii::$app->getModule('userextended')->avatarPath); // Create uploadAvatar Instance $image = $model->uploadAvatar($avatarPath); // Profile Event $event = $this->getProfileEvent($model); // Ajax Validation $this->performAjaxValidation($model); $this->trigger(self::EVENT_BEFORE_PROFILE_UPDATE, $event); if ( $model->load( Yii::$app->request->post()) && $model->save()) { // revert back if no valid file instance uploaded if ($image === false) { $model->avatar = $oldImage; } else { // if is there an old image, delete it if($oldImage) { $model->deleteImage($oldImage); } // upload new avatar $model->avatar = $image->name; } Yii::$app->getSession()->setFlash('success', Yii::t('user', 'Your profile has been updated')); $this->trigger(self::EVENT_AFTER_PROFILE_UPDATE, $event); return $this->refresh(); } return $this->render('profile', [ 'model' => $model ]); } ]