public function actionAddImages(int $categoryId, int $languageId)
    {
        $this->trigger(self::EVENT_BEFORE_EDIT_CATEGORY);

        $category = Category::findOne($categoryId);
        $image_form = new CategoryImageForm();

        if (Yii::$app->request->isPost) {
            $image_form->cover = UploadedFile::getInstance($image_form, 'cover');
            $image_form->thumbnail = UploadedFile::getInstance($image_form, 'thumbnail');
            $image_form->menu_item = UploadedFile::getInstance($image_form, 'menu_item');

            if (!empty($image_form->cover) || !empty($image_form->thumbnail) || !empty($image_form->menu_item)) {
                $image_name = $image_form->upload();

                if (!empty($image_form->cover)) {
                    $category->cover = $image_name['cover'];
                }
                if (!empty($image_form->thumbnail)) {
                    $category->thumbnail = $image_name['thumbnail'];
                }
                if (!empty($image_form->menu_item)) {
                    $category->menu_item = $image_name['menu_item'];
                }
            }
            if ($category->validate()) {
                $category->save();
                $this->trigger(self::EVENT_AFTER_EDIT_CATEGORY, new CategoryEvent(['id' => $categoryId]));
                Yii::$app->getSession()->setFlash('success', 'The images have successfully uploaded.');
            } else Yii::$app->getSession()->setFlash('error', 'Error loading image.');
        }

        return $this->render('save', [
            'viewName' => 'add-images',
            'params' => [
                'languages' => Language::findAll(['active' => true]),
                'category' => $category,
                'image_form' => $image_form,
                'selectedLanguage' => Language::findOne($languageId),
            ],
        ]);
    }
public function actionAddImages(int $categoryId, int $languageId)
    {
        $this->trigger(self::EVENT_BEFORE_EDIT_CATEGORY);

        $category = Category::findOne($categoryId);
        $image_form = new CategoryImageForm();

        if (Yii::$app->request->isPost) {
            $image_form->cover = UploadedFile::getInstance($image_form, 'cover');
            $image_form->thumbnail = UploadedFile::getInstance($image_form, 'thumbnail');
            $image_form->menu_item = UploadedFile::getInstance($image_form, 'menu_item');

            if (!empty($image_form->cover) || !empty($image_form->thumbnail) || !empty($image_form->menu_item)) {
                $image_name = $image_form->upload();

                if (!empty($image_form->cover)) {
                    $category->cover = $image_name['cover'];
                }
                if (!empty($image_form->thumbnail)) {
                    $category->thumbnail = $image_name['thumbnail'];
                }
                if (!empty($image_form->menu_item)) {
                    $category->menu_item = $image_name['menu_item'];
                }
            }
            if ($category->validate()) {
                $category->save();
                $this->trigger(self::EVENT_AFTER_EDIT_CATEGORY, new CategoryEvent(['id' => $categoryId]));
                Yii::$app->getSession()->setFlash('success', 'The images have successfully uploaded.');
            } else Yii::$app->getSession()->setFlash('error', 'Error loading image.');
        }

        return $this->render('save', [
            'viewName' => 'add-images',
            'params' => [
                'languages' => Language::findAll(['active' => true]),
                'category' => $category,
                'image_form' => $image_form,
                'selectedLanguage' => Language::findOne($languageId),
            ],
        ]);
    }
public function actionAddImages ( int $ categoryId , int $ languageId ) { $ this -> trigger ( self :: EVENT_BEFORE_EDIT_CATEGORY ) ; $ category = Category :: findOne ( $ categoryId ) ; $ image_form = new CategoryImageForm ( ) ; if ( Yii :: $ app -> request -> isPost ) { $ image_form -> cover = UploadedFile :: getInstance ( $ image_form , 'cover' ) ; $ image_form -> thumbnail = UploadedFile :: getInstance ( $ image_form , 'thumbnail' ) ; $ image_form -> menu_item = UploadedFile :: getInstance ( $ image_form , 'menu_item' ) ; if ( ! empty ( $ image_form -> cover ) || ! empty ( $ image_form -> thumbnail ) || ! empty ( $ image_form -> menu_item ) ) { $ image_name = $ image_form -> upload ( ) ; if ( ! empty ( $ image_form -> cover ) ) { $ category -> cover = $ image_name [ 'cover' ] ; } if ( ! empty ( $ image_form -> thumbnail ) ) { $ category -> thumbnail = $ image_name [ 'thumbnail' ] ; } if ( ! empty ( $ image_form -> menu_item ) ) { $ category -> menu_item = $ image_name [ 'menu_item' ] ; } } if ( $ category -> validate ( ) ) { $ category -> save ( ) ; $ this -> trigger ( self :: EVENT_AFTER_EDIT_CATEGORY , new CategoryEvent ( [ 'id' => $ categoryId ] ) ) ; Yii :: $ app -> getSession ( ) -> setFlash ( 'success' , 'The images have successfully uploaded.' ) ; } else Yii :: $ app -> getSession ( ) -> setFlash ( 'error' , 'Error loading image.' ) ; } return $ this -> render ( 'save' , [ 'viewName' => 'add-images' , 'params' => [ 'languages' => Language :: findAll ( [ 'active' => true ] ) , 'category' => $ category , 'image_form' => $ image_form , 'selectedLanguage' => Language :: findOne ( $ languageId ) , ] , ] ) ; }
Adds category images

@param integer $languageId
@param integer $categoryId
@return mixed
@throws Exception
Adds category images