here’s where I use the CSS to display the image (in my main.php layout)
$this->widget('bootstrap.widgets.TbNavbar', array(
'htmlOptions' => array('class' => 'navbar-fixed-top'),
'type'=>'inverse', // null or 'inverse'
'brand'=>'',
'brandOptions'=>array(),
'collapse'=>true, // requires bootstrap-responsive.css
'items'=>array(
array(
'class'=>'bootstrap.widgets.TbMenu',
'htmlOptions'=>array('class'=>'container_tweak pull-right' ),
'items'=>array(
array('label' => Yii::t('general',"hello ").Yii::app()->user->name, 'url'=>Yii::app()->getModule('user')->profileUrl),
array('label'=>"", 'url'=>null,'visible'=>true,'itemOptions'=>array('class'=>'user_icon')),
)),
),
),
),
)
the user_icon class being used on the last line calls this CSS code
.user_icon {
width: 50px;
height: 50px;
background-image: url('../images/users/gen/avatar.jpg');
background-repeat: no-repeat;
float:left;
}
now… my login controller calls the following
public function actionLogin()
{
if (Yii::app()->user->isGuest) {
$model=new UserLogin;
// collect user input data
if(isset($_POST['UserLogin']))
{
$model->attributes=$_POST['UserLogin'];
// validate user input and redirect to previous page if valid
if($model->validate()) {
$this->lastViset();
/* set avatar pic to current user just logged in */
$this->setUserAvatar()
if (Yii::app()->user->returnUrl=='/index.php')
$this->redirect(Yii::app()->controller->module->returnUrl);
else
$this->redirect(Yii::app()->user->returnUrl);
}
}
// display the login form
$this->render('/user/login',array('model'=>$model));
} //else
$this->redirect(Yii::app()->controller->module->returnUrl);
}
and here’s the setUserAvatar() function
private function setUserAvatar(){
$users=User::model()->findByPk($id);
$basefile = Yii::getPathOfAlias('webroot.images.users').'/'.$img.'';
$targetfle =Yii::getPathOfAlias('webroot.images.users').'/gen/avatar.jpg';
copy($basefile,$targetfle)
}
so that’s the code being used. so for some reason after a successful login the image changes in the file system then the redirect happens and still uses whatever pic the avatar.jpg was previously set to. hit refresh once and the new pic comes up