Use expand in actionMyfunction()

I am developing REST API and I have an action Myfunction() and i wand to use expand
Here is my code

public function actionMyfunction() {
 $query = $this->model::find();
 $query->someCondition()->all();
  return $query
 }

My Model is

 public function fields() {
    return [
        'id',
        'name',
    ];
}

public function extraFields() {
     return ['status'];
}

This url not working for me
v1/userroles/myfunction?expand=status

Thanks

@samdark will you help ?

Maybe i could help you. :slight_smile:

What do you get there? a 404 ?

Have you enabled prettyUrls?

https://www.yiiframework.com/doc/guide/2.0/en/runtime-routing#using-pretty-urls

Have you checked yii-debug ?

Here is explained, how you could use it : https://www.yiiframework.com/extension/yiisoft/yii2-debug

From which Controller are you extending ?

yii/web/controller or yii/rest/controller?

1 Like

Extend from yii/rest/controller ActiveController
@demonking

Can you answer my other questions? :slight_smile:

yes i am using pretty url and debugging

does it work without params?

v1/userroles/myfunction

with or without param its give one result. Not give status

if status is just a db field or property and not a model relation, then it won’t work because extraFields() is used to return data from a relation.

1 Like