A
A
AlexAll2018-10-27 16:11:12
Yii
AlexAll, 2018-10-27 16:11:12

Why Bad Request image (#400) in yii2?

I am editing a post, when I click Save, I get an error Bad Request (# 400)
I found out that the error is due to the output of the picture, if this code is removed from the form view

<?php 
   $img = $image->getPostImg($model->id);

           if(!empty($img->name)){
                
                 echo Html::img('https://site.ku/frontend/web/' . $img->name, $options = ['id' => 'blah', 'style' => ['width' => '180px']]);
            } 

?>

then the error disappears and everything is saved, the field itself remains and works fine
<?= $form->field($image, 'image')->fileInput(['id' => 'images-image', 'name' => 'Images[image]']) ?>

And when I go to edit the post and look at the source code, there is a picture there, but it is not displayed, and when you click on the link of this picture, they give the same error, but the picture is there
<img id="blah" src="https://site.ku/frontend/web/uploads/post/post_5bd33b14ab799.png" alt="" style="width: 180px;">

I do it in the admin panel in the backend from the admin with registered access and save the pictures in the frontend
'access' => [
                'class' => AccessControl::className(),
                'rules' => [
                    [
                        'allow' => true,
                        'roles' => ['AdminPanel'],
                    ],
                ],
            ],

I take it this is a permissions error? what's wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kirill Arutyunov, 2018-10-27
@arutyunov

Check if the form has a CSRF token. Most often, this error is precisely because of him. Especially if the logs say "failed to check the data."

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question