Answer the question
In order to leave comments, you need to log in
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
],
public $image;
public function behaviors(){
return [
'image' => [
'class' => 'rico\yii2images\behaviors\ImageBehave',
]
];
}
); 'image')->fileInput()
=$form->field($model, 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]);
}
Answer the question
In order to leave comments, you need to log in
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] => Значение «Новый» должно быть строкой.
)
)
$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!
Described the upload function (but for some reason saveAs is highlighted in yellow)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question