Use expand in actionMyfunction()


(Faizan Khattak) #1

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

(Faizan Khattak) #2

@samdark will you help ?


(demonking) #3

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?


(Faizan Khattak) #4

Extend from yii/rest/controller ActiveController
@demonking


(demonking) #5

Can you answer my other questions? :slight_smile:


(Faizan Khattak) #6

yes i am using pretty url and debugging


(demonking) #7

does it work without params?

v1/userroles/myfunction

(Faizan Khattak) #8

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


(Eric) #9

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.