Array Parameters In Http Requests


I need to implement a web service with Yii but the service specification makes use of array parameters in GET requests.

These params look like this:[foo]=bar&p[a]=b

The action in the controller is:

public function actionSearch($p=array()) { ... }

Yii generates a HTTP Error 400 (Your request is invalid). How can I handle this ? Is it possible to post-process the request ?

Thank you for your help,


Since reflection is used for named params binding (at least for Yii2) you need to define param type explicitly.

So try this:

public function actionSearch(array $p=array()) { ... }

The thing is, assigning array() to function param only sets the default value for it, it tells nothing about param type, so reflection’s isArray() returns false.

Type hinting was introduced in php5.1, I’m pretty sure you have >=5.1 version.