What are the typical scenarios in which the standalone operation in Yii is used?

Source: Internet
Author: User
is this controller-independent operation generally used in what circumstances? I've been thinking about it for a long time and I haven't found out where it's going to be in real development (and I think it will result in a coupling between the two controllers)

Standalone operation

An independent operation is defined by inheriting yiibaseaction or its subclasses.
For example, Yii releases Yiiwebviewaction and yiiweberroraction are independent operations.

To use stand-alone operations, you need to override the Yiibasecontroller::actions () method through the controller in the action
The map declares, as shown in the following example:

Public function actions () {

return [    // 用类来申明"error" 操作    'error' => 'yii\web\ErrorAction',    // 用配置数组申明 "view" 操作    'view' => [        'class' => 'yii\web\ViewAction',        'viewPrefix' => '',    ],]; } 如上所示, actions() 方法返回键为操作ID、值为对应操作类名或数组configurations 的数组。 和内联操作不同,独立操作ID可包含任意字符,只要在actions() 方法中申明.

To create a standalone action class, you need to inherit yiibaseaction or its subclasses, and implement the public name of the run () method, run ()
The role of the method is similar to the action method, for example:

Use yiibaseaction;

Class Helloworldaction extends Action {

public function run(){    return "Hello World";}

}

Reply content:

is this controller-independent operation generally used in which cases? I've been thinking about it for a long time, and I haven't found out where it's going to be in real development (and I think that would result in a coupling between two controllers)

Standalone operation

An independent operation is defined by inheriting yiibaseaction or its subclasses.
For example, Yii releases Yiiwebviewaction and yiiweberroraction are independent operations.

To use stand-alone operations, you need to override the Yiibasecontroller::actions () method through the controller in the action
The map declares, as shown in the following example:

Public function actions () {

return [    // 用类来申明"error" 操作    'error' => 'yii\web\ErrorAction',    // 用配置数组申明 "view" 操作    'view' => [        'class' => 'yii\web\ViewAction',        'viewPrefix' => '',    ],]; } 如上所示, actions() 方法返回键为操作ID、值为对应操作类名或数组configurations 的数组。 和内联操作不同,独立操作ID可包含任意字符,只要在actions() 方法中申明.

To create a standalone action class, you need to inherit yiibaseaction or its subclasses, and implement the public name of the run () method, run ()
The role of the method is similar to the action method, for example:

Use yiibaseaction;

Class Helloworldaction extends Action {

public function run(){    return "Hello World";}

}

Yii2 's own verification code is a typical use case

  • Related Article

    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.