How to accept both $_GET and $_POST request params?

Hello,

I am working on api. In which there is requirement to accept both parameters using $_GET and $_POST methods.

So how to handle this request in Yii2?

Yes. I have option to use $_REQUEST but how to do in Yii2?

1 Like

Just get them both via…




Yii::$app->request->post()

Yii::$app->request->get()

You can still get both of them no matter what request type is sent.

Then you can work with them how you like? If you prefer them to act like $_REQUEST then just use $_REQUEST. :)

Hi,

Additional to what gutterboy said - read the guide on requests:

http://www.yiiframework.com/doc-2.0/guide-runtime-requests.html

Regards

@gutterboy and @MetaCrawler Thanks you.

But I have to accept both so i have used $_REQUEST.

You can keep the benefits of using Yii request methods by merging both result arrays so you will get your $_REQUEST.

Yes. I think this is the right way to use yii2 request method by merge them.