Hello. I want save user last login date, so I decided to do it in event. Creating own event and attaching it to function saving timestamp is easy, just follow But I would prefer using built-in yii\web\user::EVENT_AFTER_LOGIN. This is my code:

class User extends ActiveRecord implements IdentityInterface {

   public function init(){

      $this->on(User::EVENT_AFTER_LOGIN, [$this, 'updateLastLogin']);


I am getting error: Undefined class constant ‘EVENT_AFTER_LOGIN’. I also tried IdentityInterface::EVENT_AFTER_LOGIN, but they both seem not be connected with yii\web\user. What is proper way to use this event?

Class yii/web/User extends class Component, but your class User extends ActiveRecord

and dont have such constants and events.

You can redeclare your own method afterLogin

Or try to use yii\web\User::EVENT_AFTER_LOGIN