displaying data from db in a div

I want to display data from the db in a div, I’m using this statement to retrieve all the records I need,

$everyone_in_the_room = User::model()->findAll(‘LOWER(room_name)=?’, array($_SESSION[‘roomName’]));

this does retrieve the records, now I want to pass that data to a view and display some of it in a div, the usernames specifically. I’m trying to pass the data like this


firstly, how do I access that data in the view that I’ve passed it to. Secondly, is that the best way to do it?

In the view you access it by the array key you assigned to when passing to the render method, so it will be:


// other exp: controller


// view file:

echo $a; // 1

echo $b; // 2

Yes that’s the way you pass the data.

foreach($everyone_in_the_room as $person_in_the_room) {

	echo $person_in_the_room->first_name . '<br/>';


Thanks twisted 1919. Here’s my problem though, the statement $everyone_in_the_room = User::model()->findAll(‘LOWER(room_name)=?’, array($_SESSION[‘roomName’])); returns a huge object with a crap load of metadata and I can’t get to the value I need. The user model is just this







How do I get at the values I need, am I making sense?

Jacmoe, you rock!!!

I know.

But only because Yii rocks!

OK here’s another question, how do I make a CHtml link only visible to certain users. What I need is to make a link visible based on a certain value in the current users table in the db if you get me. As the post above shows, the user table has a is_moderator field. I need to check that value of the currently logged in user and set the link to be visible or not. Does that make sense? Appreciate all the input from everyone by the way, this forum’s been a great help.

You can use setState to set a user’s role at login in your UserIdentity component (see Guide).

Then, in your views:

if(Yii::app()->user->role == 'is_moderator')

    //echo something

If you don’t want to set a global role in your UserIdentity you can do this:


if($member->is_moderator == 1)

    //echo something

Just curious - why are you putting that data in session?

Thanks waitforit, that worked a charm. As for the data being stored in a session, I assume you’re referring to the $_SESSION[‘roomName’] piece of code. The room name is something that would be useful to get at throughout the application, I’m sure there are probably better alternatives but given I’m a novice at php and Yii, that was the only solution I could think of.

Thanks again