I have to perform some operations after the user logs in, but I don’t want to change so much my UserIdentity class to do this
My question is:
Is there any way to create an afterLogin event and attach it to my User model and so raise the event in the Login action?
Something like this?
1 -> User Performs Login
2 -> My controller raises User::afterLogin event
3 -> User::afterLogin event takes care of some changes in database
Any help is appreciated
PS.: I’ve read Yii’s documentation and cookbook, but both are helpless on Events
Read this cookbook page about events:
You should attach an event handler (or some handlers) to the event onAfterLogin. It will look like:
public function authenticate()
$this->onAfterLogin = array(new MyClass, 'helpfulMethod');
public function onAfterLogin($event)
public function helpfulMethod($event)
echo 'Hi, '.Yii::app()->user->id.'!';
I’ve had already read the cookbook post you’ve mentioned, however, your explanation is way better, meaning a real world sample, which is exactly what I need.
Very useful and appreciated!
Thanks a lot!!!
Hey Junior. Have you had success using this method? I’m trying to solve this for a while and until now nothing…