W3cubDocs

/Yii 2.0

Class yii\base\ActionFilter

Inheritance yii\base\ActionFilter » yii\base\Behavior » yii\base\Object
Implements yii\base\Configurable
Subclasses yii\filters\AccessControl, 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\QueryParamAuth
Available since version 2.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

Property Type Description Defined 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 The owner of this behavior yii\base\Behavior

Public Methods

Method Description Defined By
__call() Calls the named method which is not a class method. yii\base\Object
__construct() Constructor. yii\base\Object
__get() Returns the value of an object property. yii\base\Object
__isset() Checks if a property is set, i.e. defined and not null. yii\base\Object
__set() Sets value of an object property. yii\base\Object
__unset() Sets an object property to null. yii\base\Object
afterAction() This method is invoked right after an action is executed. yii\base\ActionFilter
afterFilter() yii\base\ActionFilter
attach() Attaches the behavior object to the component. 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\Object
canSetProperty() Returns a value indicating whether a property can be set. yii\base\Object
className() Returns the fully qualified name of this class. yii\base\Object
detach() Detaches the behavior object from the component. 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\Object
hasProperty() Returns a value indicating whether a property is defined. yii\base\Object
init() Initializes the object. yii\base\Object

Protected Methods

Method Description Defined 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

Attaches the behavior object to the component.

The default implementation will set the $owner property and attach event handlers as declared in events(). Make sure you call the parent implementation if you override this method.

public void attach ( $owner )
$owner yii\base\Component

The component that this behavior is to be attached to.

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

Detaches the behavior object from the component.

The default implementation will unset the $owner property and detach event handlers declared in events(). Make sure you call the parent implementation if you override this method.

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.

© 2008–2017 by Yii Software LLC
Licensed under the three clause BSD license.
http://www.yiiframework.com/doc-2.0/yii-base-actionfilter.html