When you call Yii::app()->user->id
, the user
part is a instance of the CWebUser
class (or a child of that class).
When the application loads, it tries to initialize that user
component, and as part of that initialization, it logs in a user, and then calls your overridden afterLogin
method. Your afterLogin
method in turn tries to call the component... but it hasn't finished initializing yet. So rather than get stuck in an infinite loop, Yii just tells you that the user
component doesn't exist.
Fortunately, during the login process, a call to changeIdentity
is made, which calls setId
, which populates the $id
attribute of the user
component. This id
attribute is in fact exactly the same attribute that is called with Yii::app()->user->id
, only it is accessed within the object, instead of externally.