php - how create afterAction for every method of controller in yii2? -
is afteraction works every action of controller in yii2????
if not how should make afteraction every method of controller???
yes, afteraction() event handler triggers every action in controller.
take @ official docs method:
this method invoked right after action executed.
the method trigger
event_after_action event. return value of method used action return value.if override method, code should following:
public function afteraction($action, $result) { $result = parent::afteraction($action, $result); // custom code here return $result; } if need limit execution of code specific actions, can use $action variable this:
for single action:
if ($action->id == '...') { ... } for multiple actions:
if (in_array($action->id, [..., ...]) { ... } or can use $action->uniqueid instead.
Comments
Post a Comment