A RESTful style project is being developed with YII2.0.0 recently.
There is a small problem: when I want to customize the output data or custom input data operations, you must write your own class to inherit from the corresponding Action shape:
public function actions(){ $actions = parent::actions(); //index操作还能指定controller里面的函数,类似如下 $actions['index']['prepareDataProvider'] = [$this, 'prepareDataProvider']; //其他action只能自己指定继承自yii\rest\XXXAction的类,然后在类里面重写run函数 $actions['create'] = 'app\my_actions\controller_name\CreateAction'; return $actions;}
Is there any way to specify a function in the controller like the index operation instead of rewriting the corresponding run function?
Reply content:
A RESTful style project is being developed with YII2.0.0 recently.
There is a small problem: when I want to customize the output data or custom input data operations, you must write your own class to inherit from the corresponding Action shape:
public function actions(){ $actions = parent::actions(); //index操作还能指定controller里面的函数,类似如下 $actions['index']['prepareDataProvider'] = [$this, 'prepareDataProvider']; //其他action只能自己指定继承自yii\rest\XXXAction的类,然后在类里面重写run函数 $actions['create'] = 'app\my_actions\controller_name\CreateAction'; return $actions;}
Is there any way to specify a function in the controller like the index operation instead of rewriting the corresponding run function?