V
V
Vladimir2016-09-20 13:28:50
Yii
Vladimir, 2016-09-20 13:28:50

Why is the image not loading in Yii2?

Good day! I can't figure out why the image doesn't load. I am using yii2 images.
I did everything according to the instructions
1) Installed the module itself
2) Launched the migration
3) Connected the module

'yii2images' => [
            'class' => 'rico\yii2images\Module',
            //be sure, that permissions ok
            //if you cant avoid permission errors you have to create "images" folder in web root manually and set 777 permissions
            'imagesStorePath' => 'images/store', //path to origin images
            'imagesCachePath' => 'images/cache', //path to resized copies
            'graphicsLibrary' => 'GD', //but really its better to use 'Imagick'
            'placeHolderPath' => '@webroot/images/placeHolder.png', // if you want to get placeholder when image not exists, string will be processed by Yii::getAlias
        ],

4) Registered behavior
public $image;
    
    public function behaviors(){
        return [
            'image' => [
                'class' => 'rico\yii2images\behaviors\ImageBehave',
            ]
        ];
    }

5) Set the rules 6) Described the upload function (but for some reason saveAs is highlighted in yellow)
); ?> <?=$form->field($model, 'image')->fileInput() ?>
8) In the web folder, I created the images / store, images / cache folders
9) But what is in actionUpdate ()
if ($model->load(Yii::$app->request->post()) && $model->save()) {
            $model->image = UploadedFile::getInstance($model, 'image');
            if ($model->image){
                $model->upload();
            }

            return $this->redirect(['view', 'id' => $model->id]);
        }

Tell me, please, what can it be? I will be very grateful!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir, 2016-09-21
@MasterGerold

That's where the mistake was!
I have a field that was written in beforeSave in the model as follows:
Then I made an output of the object that should be processed, everything was perfect there ... but this line was the only error that I have not seen until today.

[_errors:yii\base\Model:private] => Array
        (
            [new] => Array
                (
                    [0] => Значение «Новый» должно быть строкой.
                )

        )

And changing $this->new = 0;to $this->new = '0';Everything worked for me! But I can't understand how all the data was updated correctly, but the picture didn't want to? But the main thing is that everything works and the cause of the malfunction was found! Many thanks to Maxim Temofeev for constant help!

M
Maxim Timofeev, 2016-09-20
@webinar

Described the upload function (but for some reason saveAs is highlighted in yellow)

because the editor has no idea that $this->image is an object and has a method like this
What are the errors in debug?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question