ActionFilter
API reference › yii › base › ActionFilter
9 subclasses
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 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.
Properties
Section titled “Properties”| Property | Type | Description | Defined by |
|---|---|---|---|
$except | array | List of action IDs that this filter should not apply to. Default: []. | ActionFilter |
$only | array | List of action IDs that this filter should apply to. Default: []. | ActionFilter |
$owner | yii\ | The owner of this behavior Default: null. | Behavior |
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
__construct() | Constructor. | BaseObject |
__call() | Calls the named method which is not a class method. | BaseObject |
__get() | Returns the value of an object property. | BaseObject |
__isset() | Checks if a property is set, i.e. defined and not null. | BaseObject |
__set() | Sets value of an object property. | BaseObject |
__unset() | Sets an object property to null. | BaseObject |
afterAction() | This method is invoked right after an action is executed. | ActionFilter |
afterFilter() | ActionFilter | |
attach() | Attaches the behavior object to the component. | 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. | ActionFilter |
beforeFilter() | ActionFilter | |
canGetProperty() | Returns a value indicating whether a property can be read. | BaseObject |
canSetProperty() | Returns a value indicating whether a property can be set. | BaseObject |
className() static | Returns the fully qualified name of this class. | BaseObject |
detach() | Detaches the behavior object from the component. | ActionFilter |
events() | Declares event handlers for the $owner’s events. | Behavior |
hasMethod() | Returns a value indicating whether a method is defined. | BaseObject |
hasProperty() | Returns a value indicating whether a property is defined. | BaseObject |
init() | Initializes the object. | BaseObject |
getActionId() protected | Returns an action ID by converting Action::$uniqueId into an ID relative to the module. | ActionFilter |
isActive() protected | Returns a value indicating whether the filter is active for the given action. | ActionFilter |
Property details
Section titled “Property details”$only
Section titled “$only ”public array $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/*.
Method details
Section titled “Method details”afterAction()
Section titled “afterAction() ”public function afterAction(yii\base\Action $action, mixed $result): mixedThis method is invoked right after an action is executed.
You may override this method to do some postprocessing for the action.
Parameters
| Parameter | Type | Description |
|---|---|---|
$action | Action | The action just executed. |
$result | mixed | The action execution result |
Returns
mixed: The processed action result.
afterFilter()
Section titled “afterFilter() ”public function afterFilter(yii\base\ActionEvent $event): mixedattach()
Section titled “attach() ”public function attach(mixed $owner): mixedAttaches 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.
Parameters
| Parameter | Type | Description |
|---|---|---|
$owner | mixed | The component that this behavior is to be attached to. |
Returns
mixed
beforeAction()
Section titled “beforeAction() ”public function beforeAction(yii\base\Action $action): boolThis 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.
Parameters
| Parameter | Type | Description |
|---|---|---|
$action | Action | The action to be executed. |
Returns
bool: Whether the action should continue to be executed.
beforeFilter()
Section titled “beforeFilter() ”public function beforeFilter(yii\base\ActionEvent $event): mixeddetach()
Section titled “detach() ”public function detach(): mixedDetaches 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.
Returns
mixed
getActionId()
Section titled “getActionId() ”protected function getActionId(yii\base\Action $action): stringReturns an action ID by converting Action::$uniqueId into an ID relative to the module.
isActive()
Section titled “isActive() ”protected function isActive(yii\base\Action $action): boolReturns a value indicating whether the filter is active for the given action.
Parameters
| Parameter | Type | Description |
|---|---|---|
$action | Action | The action being filtered |
Returns
bool: Whether the filter is active for the given action.