I tried to implement what I wanted (e.g. Yii::app()->user->getFirstname() ), but could not achieve, may be due to my limited knowledge about the Yii framework and too many files involved in implementing user and authentication. (UserIdentity.php, User.php, cUserIdentiry.php, CWebUser.php and many more, and I did not want to modify any Framework files.)
Anyway, I achieved what I wanted through Session in the authenticate method of protected/components/UserIdentity.php as shown here.
// Added to save details about the logged-in user
Yii::app()->session['user_firstname'] = $user->firstname;
Yii::app()->session['user_lastname'] = $user->lastname;
Yii::app()->session['user_fullname'] = trim($user->firstname). ' ' . trim($user->lastname);
Yii::app()->session['user_email'] = $user->email;
I would still prefer if I can implement my original scheme, i.e. Yii::app()->user->getFirstname()
, however, my workaround works through <?php echo "Email= " . Yii::app()->session['user_email'] . "<BR>" ?>
. I don't know whether saving non-sensitive data in session
will lead to any security issues. Any comments?