Class yii\base\Action

继承yii\base\Action » yii\base\Component » yii\base\BaseObject
实现yii\base\Configurable
子类yii\base\InlineAction, yii\captcha\CaptchaAction, yii\rest\Action, yii\rest\CreateAction, yii\rest\DeleteAction, yii\rest\IndexAction, yii\rest\OptionsAction, yii\rest\UpdateAction, yii\rest\ViewAction, yii\web\ErrorAction, yii\web\ViewAction
可用自版本2.0
源代码 https://github.com/yiisoft/yii2/blob/master/framework/base/Action.php

Action is the base class for all controller action classes.

Action provides a way to reuse action method code. An action method in an Action class can be used in multiple controllers or in different projects.

Derived classes must implement a method named run(). This method will be invoked by the controller when the action is requested. The run() method can have parameters which will be filled up with user input values automatically according to their names. For example, if the run() method is declared as follows:

public function run($id, $type = 'book') { ... }

And the parameters provided for the action are: ['id' => 1]. Then the run() method will be invoked as run(1) automatically.

For more details and usage information on Action, see the guide article on actions.

公共属性

隐藏继承的属性

属性类型描述定义在
$behaviors yii\base\Behavior[] 附加到此组件的行为列表. yii\base\Component
$controller yii\base\Controller|yii\web\Controller|yii\console\Controller The controller that owns this action yii\base\Action
$id string ID of the action yii\base\Action
$uniqueId string The unique ID of this action among the whole application. yii\base\Action

公共方法

隐藏继承的方法

方法描述定义在
__call() 调用不是类方法的已命名方法. yii\base\BaseObject
__clone() 在通过克隆现有对象创建对象之后调用此方法. yii\base\Component
__construct() Constructor. yii\base\Action
__get() 返回对象属性的值. yii\base\BaseObject
__isset() 检查属性是否已设置, 即已定义且不为null. yii\base\BaseObject
__set() 设置对象属性的值. yii\base\BaseObject
__unset() 将对象属性设置为null. yii\base\BaseObject
attachBehavior() 将行为附加到此组件. yii\base\Component
attachBehaviors() 将行为列表附加到组件. yii\base\Component
behaviors() 返回此组件应该具有的行为列表. yii\base\Component
canGetProperty() 返回一个值, 指示属性是否可读. yii\base\BaseObject
canSetProperty() 返回一个值, 指示属性是否可写. yii\base\BaseObject
className() 返回此类的完全限定名称. yii\base\BaseObject
detachBehavior() 从组件中分离一个行为. yii\base\Component
detachBehaviors() 分离组件中的所有行为. yii\base\Component
ensureBehaviors() 确保在 behaviors() 中声明的行为已附加到此组件. yii\base\Component
getBehavior() 返回指定的行为对象. yii\base\Component
getBehaviors() 返回附加到此组件的所有行为. yii\base\Component
getUniqueId() Returns the unique ID of this action among the whole application. yii\base\Action
hasEventHandlers() 返回一个值, 指示是否有任何处理程序附加到指定的事件. yii\base\Component
hasMethod() 返回一个值, 指示方法是否已定义. yii\base\BaseObject
hasProperty() 返回一个值, 指示属性是否已定义. yii\base\BaseObject
init() 初始化对象. yii\base\BaseObject
off() 从该组件分离现有的事件处理程序. yii\base\Component
on() 将事件处理程序附加到事件. yii\base\Component
runWithParams() Runs this action with the specified parameters. yii\base\Action
trigger() 触发事件. yii\base\Component

受保护的方法

隐藏继承的方法

方法描述定义在
afterRun() This method is called right after run() is executed. yii\base\Action
beforeRun() This method is called right before run() is executed. yii\base\Action

属性详情

$controller public 属性

The controller that owns this action

$id public 属性

ID of the action

public string $id null
$uniqueId public 只读 属性

The unique ID of this action among the whole application.

public string getUniqueId ( )

方法详情

__construct() public 方法

Constructor.

public void __construct ( $id, $controller, $config = [] )
$id string

The ID of this action

$controller yii\base\Controller

The controller that owns this action

$config array

Name-value pairs that will be used to initialize the object properties

afterRun() protected 方法

This method is called right after run() is executed.

You may override this method to do post-processing work for the action run.

protected void afterRun ( )
beforeRun() protected 方法

This method is called right before run() is executed.

You may override this method to do preparation work for the action run. If the method returns false, it will cancel the action.

protected boolean beforeRun ( )
return boolean

Whether to run the action.

getUniqueId() public 方法

Returns the unique ID of this action among the whole application.

public string getUniqueId ( )
return string

The unique ID of this action among the whole application.

runWithParams() public 方法

Runs this action with the specified parameters.

This method is mainly invoked by the controller.

public mixed runWithParams ( $params )
$params array

The parameters to be bound to the action's run() method.

return mixed

The result of the action

throws yii\base\InvalidConfigException

if the action class does not have a run() method