By the way solution that I advised removes all actions except index. If you want leave the default set of actions, the code should be like that:
public function actions()
{
$actions = parent::actions();
$actions['index']['prepareDataProvider'] = [$this, 'prepareDataProvider'];
return $actions;
}
I don’t completely understood your last sentence.
You should put this code in controller which extends from yii\rest\ActiveController and add corresponding url rule in urlManager component in config, so the action from default transforms to rest action.
The index action called by GET and HEAD requests, so it will be available through browser by just calling that url.
And the question was about getting data without adding url parameter.
I know this topic is old, but for me it’s not working as expected. I too would like to get Users with country but without expand parameter. I have all relations set up properly.
I have the following simple query in my search action:
$provider = new ActiveDataProvider([
'query' => User::find()->with('country');
]);
when I do GET /users?expand=country my REST API returns all users with country as expected. But when I omit the expand=country parameter I get back just users without country, even though my query includes relation [font=“Courier New”]->with(‘country’)[/font]. What is it not returning whatever is in the object?
I would like to omit expand parameter because I need to return deeper relations as well which expand does not support.