Class yii\base\ActionFilter

Inheritanceyii\base\ActionFilter » yii\base\Behavior » yii\base\BaseObject
Implementsyii\base\Configurable
Subclassesyii\filters\AccessControl, yii\filters\AjaxFilter, yii\filters\ContentNegotiator, yii\filters\Cors, yii\filters\HostControl, yii\filters\HttpCache, yii\filters\PageCache, yii\filters\RateLimiter, yii\filters\auth\AuthMethod, yii\filters\auth\CompositeAuth, yii\filters\auth\HttpBasicAuth, yii\filters\auth\HttpBearerAuth, yii\filters\auth\HttpHeaderAuth, yii\filters\auth\QueryParamAuth
Available since version2.0
Source Code https://github.com/yiisoft/yii2/blob/master/framework/base/ActionFilter.php

ActionFilter is the base class for action filters.

An action filter will participate in the action execution workflow by responding to the beforeAction and afterAction events triggered by modules and controllers.

Check implementation of yii\filters\AccessControl, yii\filters\PageCache and yii\filters\HttpCache as examples on how to use it.

For more details and usage information on ActionFilter, see the guide article on filters.

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$except array List of action IDs that this filter should not apply to. yii\base\ActionFilter
$only array List of action IDs that this filter should apply to. yii\base\ActionFilter
$owner yii\base\Component|null The owner of this behavior yii\base\Behavior

Public Methods

Hide inherited methods

MethodDescriptionDefined By
__call() Calls the named method which is not a class method. yii\base\BaseObject
__construct() Constructor. yii\base\BaseObject
__get() Returns the value of an object property. yii\base\BaseObject
__isset() Checks if a property is set, i.e. defined and not null. yii\base\BaseObject
__set() Sets value of an object property. yii\base\BaseObject
__unset() Sets an object property to null. yii\base\BaseObject
afterAction() This method is invoked right after an action is executed. yii\base\ActionFilter
afterFilter() yii\base\ActionFilter
attach() {@inheritdoc} yii\base\ActionFilter
beforeAction() This method is invoked right before an action is to be executed (after all possible filters.) You may override this method to do last-minute preparation for the action. yii\base\ActionFilter
beforeFilter() yii\base\ActionFilter
canGetProperty() Returns a value indicating whether a property can be read. yii\base\BaseObject
canSetProperty() Returns a value indicating whether a property can be set. yii\base\BaseObject
className() Returns the fully qualified name of this class. yii\base\BaseObject
detach() {@inheritdoc} yii\base\ActionFilter
events() Declares event handlers for the $owner's events. yii\base\Behavior
hasMethod() Returns a value indicating whether a method is defined. yii\base\BaseObject
hasProperty() Returns a value indicating whether a property is defined. yii\base\BaseObject
init() Initializes the object. yii\base\BaseObject

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
getActionId() Returns an action ID by converting yii\base\Action::$uniqueId into an ID relative to the module. yii\base\ActionFilter
isActive() Returns a value indicating whether the filter is active for the given action. yii\base\ActionFilter

Property Details

$except public property

List of action IDs that this filter should not apply to.

See also $only.

public array $except = []
$only public property

List of action IDs that this filter should apply to. If this property is not set, then the filter applies to all actions, unless they are listed in $except. If an action ID appears in both $only and $except, this filter will NOT apply to it.

Note that if the filter is attached to a module, the action IDs should also include child module IDs (if any) and controller IDs.

Since version 2.0.9 action IDs can be specified as wildcards, e.g. site/*.

See also $except.

public array $only null

Method Details

afterAction() public method

This method is invoked right after an action is executed.

You may override this method to do some postprocessing for the action.

public mixed afterAction ( $action, $result )
$action yii\base\Action

The action just executed.

$result mixed

The action execution result

return mixed

The processed action result.

afterFilter() public method

public void afterFilter ( $event )
$event yii\base\ActionEvent
attach() public method

{@inheritdoc}

public void attach ( $owner )
$owner
beforeAction() public method

This method is invoked right before an action is to be executed (after all possible filters.) You may override this method to do last-minute preparation for the action.

public boolean beforeAction ( $action )
$action yii\base\Action

The action to be executed.

return boolean

Whether the action should continue to be executed.

beforeFilter() public method

public void beforeFilter ( $event )
$event yii\base\ActionEvent
detach() public method

{@inheritdoc}

public void detach ( )
getActionId() protected method (available since version 2.0.7)

Returns an action ID by converting yii\base\Action::$uniqueId into an ID relative to the module.

protected string getActionId ( $action )
$action yii\base\Action
isActive() protected method

Returns a value indicating whether the filter is active for the given action.

protected boolean isActive ( $action )
$action yii\base\Action

The action being filtered

return boolean

Whether the filter is active for the given action.