Impersonate User

I am trying to allow an admin to login as another user. I am following the tutorial on this page:

http://www.yiiframework.com/wiki/154/impersonate-users-within-yii-framework/

It looks like the UserIdentity object is populated correctly, but when I try to call Yii::app()->user->login($identity,0), it looks like it is not logging in the user.

Here are the arrays returned during this process. Any help is appreciated. I am using v 1.1.15.


UserIdentity Object

(

    [_id:UserIdentity:private] => 3

    [_user:UserIdentity:private] => UserAccount Object

        (

            [_new:CActiveRecord:private] => 

            [_attributes:CActiveRecord:private] => Array

                (

                    [id] => 3

                    [email] => realuser@domain.com

                    [password] => $hashedpasswordisgood

                    [firstName] => Real

                    [lastName] => User

                )

 

 

 

            [_c:CActiveRecord:private] => 

            [_pk:CActiveRecord:private] => 3

            [_alias:CActiveRecord:private] => t

            [_errors:CModel:private] => Array

                (

                )

 

            [_validators:CModel:private] => 

            [_scenario:CModel:private] => update

            [_e:CComponent:private] => 

            [_m:CComponent:private] => 

        )

 

    [username] => realuser@domain.com

    [password] => 

    [errorCode] => 0

    [errorMessage] => 

    [_state:CBaseUserIdentity:private] => Array

        (

            [email] => realuser@domain.com

            [firstName] => Real

            [lastName] => User

        )

 

    [_e:CComponent:private] => 

    [_m:CComponent:private] => 

)




<?php Yii::app()->user->login($identity, 0);?>




CWebUser Object

(

    [allowAutoLogin] => 1

    [guestName] => Guest

    [loginUrl] => Array

        (

            [0] => /site/login

        )

 

    [identityCookie] => 

    [authTimeout] => 36000

    [absoluteAuthTimeout] => 

    [autoRenewCookie] => 1

    [autoUpdateFlash] => 1

    [loginRequiredAjaxResponse] => 

    [_keyPrefix:CWebUser:private] => c257a47be47a535222f61d0d689bce9e

    [_access:CWebUser:private] => Array

        (

        )

 

    [behaviors] => Array

        (

        )

 

    [_initialized:CApplicationComponent:private] => 1

    [_e:CComponent:private] => 

    [_m:CComponent:private] => 

)

Update:

Looks like it was actually working, but that printing the user object is returning that array for some other reason. When I use this line, it returns the last name of the desired user.

echo Yii::app()->user->lastName;