I am writing a interceptor to validate request and decode data received from POST. After decoding data I have to set data to $_POST
so that my all previous writer functionality will work as it is.
I have set values like below
$_POST['amount'] = $data['a'];
$_POST['currency'] = $data['c'];
I am able to get these variables using $_POST
but these values are not accessible in Yii::$app->request->post()
So my question is can I get these values by Yii::$app->request->post()
Post data is cached inside of Request
component, so any changes in $_POST
will not be reflected in Yii::$app->request->post()
. However you may use setBodyParams()
to reset this cache:
Yii::$app->request->setBodyParams(null);
$post = Yii::$app->request->post();
Or just use setBodyParams()
to set your data directly without touching $_POST
:
Yii::$app->request->setBodyParams(['amount' => $data['a'], 'currency' => $data['c']]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With