modules/admin/controllers/BannerController.php
/**
     * Creates a new Banner model.
     * If creation is successful, the browser will be redirected to the 'view' page.
     * @return mixed
     */
Creates a new Banner model.
If creation is successful, the browser will be redirected to the 'view' page.
@return mixed
Creates a new Banner model . If creation is successful the browser will be redirected to the ' view ' page . @return mixed
public function actionCreate()
    {
        $model = new Banner();
        $model->scenario = Banner::SCENARIO_CREATE;
        $banner_image = UploadedFile::getInstance($model, 'image');
        if ($model->load(Yii::$app->request->post())) {
            if (!empty($banner_image)) {
                $uploadDirPath = Yii::getAlias('@bannerImageRelativePath');
                $uploadThumbDirPath = Yii::getAlias('@bannerImageThumbRelativePath');
                $thumbImagePath = '';
                if (!is_dir($uploadDirPath)) {
                    mkdir($uploadDirPath, 0777);
                }
                if (!is_dir($uploadThumbDirPath)) {
                    mkdir($uploadThumbDirPath, 0777);
                }
                $ext = $banner_image->extension;
                $fileName = time() . rand(99999, 88888) . '.' . $ext;
                $banner_image->saveAs($uploadDirPath . '/' . $fileName);
                $actualImagePath = $uploadDirPath . '/' . $fileName;
                $thumbImagePath = $uploadThumbDirPath . '/' . $fileName;
                Image::getImagine()->open($actualImagePath)->thumbnail(new Box(Yii::$app->params['profile_picture_thumb_width'], Yii::$app->params['profile_picture_thumb_height']))->save($thumbImagePath, ['quality' => Yii::$app->params['profile_picture_thumb_quality']]);
                $model->image = $fileName;
            }
            if ($model->save()) {
                Yii::$app->session->setFlash(Growl::TYPE_SUCCESS, "Banner created successfully.");
            } else {
                Yii::$app->session->setFlash(Growl::TYPE_DANGER, "Error while creating Banner.");
            }
            return $this->redirect(['index']);
        }
        return $this->render('create', [
            'model' => $model,
        ]);
    }
public function actionCreate ( ) { $ model = new Banner ( ) ; $ model -> scenario = Banner :: SCENARIO_CREATE ; $ banner_image = UploadedFile :: getInstance ( $ model , 'image' ) ; if ( $ model -> load ( Yii :: $ app -> request -> post ( ) ) ) { if ( ! empty ( $ banner_image ) ) { $ uploadDirPath = Yii :: getAlias ( '@bannerImageRelativePath' ) ; $ uploadThumbDirPath = Yii :: getAlias ( '@bannerImageThumbRelativePath' ) ; $ thumbImagePath = '' ; if ( ! is_dir ( $ uploadDirPath ) ) { mkdir ( $ uploadDirPath , 0777 ) ; } if ( ! is_dir ( $ uploadThumbDirPath ) ) { mkdir ( $ uploadThumbDirPath , 0777 ) ; } $ ext = $ banner_image -> extension ; $ fileName = time ( ) . rand ( 99999 , 88888 ) . '.' . $ ext ; $ banner_image -> saveAs ( $ uploadDirPath . '/' . $ fileName ) ; $ actualImagePath = $ uploadDirPath . '/' . $ fileName ; $ thumbImagePath = $ uploadThumbDirPath . '/' . $ fileName ; Image :: getImagine ( ) -> open ( $ actualImagePath ) -> thumbnail ( new Box ( Yii :: $ app -> params [ 'profile_picture_thumb_width' ] , Yii :: $ app -> params [ 'profile_picture_thumb_height' ] ) ) -> save ( $ thumbImagePath , [ 'quality' => Yii :: $ app -> params [ 'profile_picture_thumb_quality' ] ] ) ; $ model -> image = $ fileName ; } if ( $ model -> save ( ) ) { Yii :: $ app -> session -> setFlash ( Growl :: TYPE_SUCCESS , " Banner created successfully. " ) ; } else { Yii :: $ app -> session -> setFlash ( Growl :: TYPE_DANGER , " Error while creating Banner. " ) ; } return $ this -> redirect ( [ 'index' ] ) ; } return $ this -> render ( 'create' , [ 'model' => $ model , ] ) ; }
Creates a new Banner model.
Creates a new Banner model .
// Create profile upload directory if not exist // Create profile thumb upload directory if not exist // Upload profile picture // Create thumb of profile picture // Insert profile picture name into database