Yii2 a small problem with the action in restful

Source: Internet
Author: User
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?

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.