0

I am making this PUT request via Postman that has form-data body: PUT request

And trying to populate the model using this line:

$model->load(Yii::$app->request->getBodyParams(), '');

Trying to print body params

See, I tried to print worker_id, time_out params of the request on debug console, but getting null. And getBodyParams() is only returning an array of one ("image") element

Getting all params

1

1 Answer 1

0

For methods other than POST Yii2 doesn't use $_POST array to get body params. It uses mb_parse_str() on raw body instead. This approach probably have problem parsing multipart request body.

To make yii2 parse multipart body properly you have to add yii\web\MultipartFormDataParser to yii\web\Request::$parsers for multipart/form-data content type.

You can add it in your config like this:

return [
    // ...
    'components' => [
        'request' => [
            'parsers' => [
                'multipart/form-data' => 'yii\web\MultipartFormDataParser'
            ],
        ],
        // ...
    ],
    // ...
];
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.