PHP Class yii\base\ActionFilter

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 AccessControl, PageCache and HttpCache as examples on how to use it. For more details and usage information on ActionFilter, see the guide article on filters.
Since: 2.0
Author: Qiang Xue ([email protected])
Inheritance: extends Behavior
Show file Open project: yiisoft/yii2 Class Usage Examples

Public Properties

Property Type Description
$except list of action IDs that this filter should not apply to.
$only 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/*.

Public Methods

Method Description
afterAction ( Action $action, mixed $result ) : mixed This method is invoked right after an action is executed.
afterFilter ( ActionEvent $event )
attach ( $owner )
beforeAction ( Action $action ) : boolean 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.
beforeFilter ( ActionEvent $event )
detach ( )

Protected Methods

Method Description
getActionId ( Action $action ) : string Returns an action ID by converting [[Action::$uniqueId]] into an ID relative to the module
isActive ( Action $action ) : boolean Returns a value indicating whether the filter is active for the given action.

Method Details

afterAction() public method

You may override this method to do some postprocessing for the action.
public afterAction ( Action $action, mixed $result ) : mixed
$action Action the action just executed.
$result mixed the action execution result
return mixed the processed action result.

afterFilter() public method

public afterFilter ( ActionEvent $event )
$event ActionEvent

attach() public method

public attach ( $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 beforeAction ( Action $action ) : boolean
$action Action the action to be executed.
return boolean whether the action should continue to be executed.

beforeFilter() public method

public beforeFilter ( ActionEvent $event )
$event ActionEvent

detach() public method

public detach ( )

getActionId() protected method

Returns an action ID by converting [[Action::$uniqueId]] into an ID relative to the module
Since: 2.0.7
protected getActionId ( Action $action ) : string
$action Action
return string

isActive() protected method

Returns a value indicating whether the filter is active for the given action.
protected isActive ( Action $action ) : boolean
$action Action the action being filtered
return boolean whether the filter is active for the given action.

Property Details

$except public property

list of action IDs that this filter should not apply to.
See also: only
public $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 $only