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