0
votes

I have one question about Yii framework, and I need your help.

Basicly, I have php statement which shows user's name.

<?php echo Yii::app()->user->name;?> 

This command will show e.g. "Harry Stamper" somewhere on page.

Imagine this scenario, I have several users, let's choose one, e.g. "John Doe" when I click on his page php statement from above will show "John Doe", as it should.

My question is: How to change this, so if I go to my page, title doesn't show "Harry Stamper" but shows "Your Page" for all members. So member home page becomes "Your Page" instead of your member name.

I think this is done with php if/else and user ID but I'm not sure how to do it in Yii. Any help would be awesome.

1
I think you are asking something which is bit explained here stackoverflow.com/questions/9786385/… - Arfeen

1 Answers

0
votes

Your scenario confuses me a little bit, as you are talking about visiting someone else's page and seeing the name of that user using the Yii::app()->user->name. Because this statement is relevant only for logged in user's name and not to be used for showing names of author or owner of pages or articles.

Yii::app()->user is an instance of the CWebUser class which is initialised when the application is run. Yii::app()->user->name will show "Guest" if the user is not logged in, else it shows the username used to login.

You can always use the function Yii::app()->user->setName() to set the full name in the login code.

Thanks