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

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -