Yii2 user beforeLogout

Dear All:

I have a question about how to implement the beforeLogout function.

I add this function in my user model but is not working.

I use yii2 basic template

Below is my class

class User extends ActiveRecord implements IdentityInterface


    public function beforeLogout()





Please help me. Thx!!!

Hi, try using like this.

'components' => [

        'user' => [

            'identityClass' => 'app\models\user\User',

            'enableAutoLogin' => true,

            'on beforeLogout' => function($event) {

                  ... code here ...




Thank you!!! It’s working for me.