passing data with render not working

I’m using render to pass data to a view but that data doesn’t seem to be visible in the view. Here is my code, I’m sure it’s something simple but I’m not well versed enough to spot it being as I’m a php novice. Would it have anything to do with the fact that the view file is outside the directory of the controller that’s calling it? If so is there a work around?

$this->render(’../room/openModeratorRoom’,array(‘user’=>$user,‘allUsers’=>$everyone_in_the_room,‘poll’=>$model));

try


$this->render('openModeratorRoom',array('user'=>$user,'allUsers'=>$everyone_in_the_room,'poll'=>$model));

tried that, I get an error saying it can’t find the view file. Thanks though

ok you need to make sure that you have the view file. Where is the file named openModeratorRoom.php located

Sorry bettor, I did’t explain that very well. It finds and renders the view just fine with my original piece of code so finding the view is not the problem, but all the data I’m passing to the openModeratorRoom view cannot be accessed in that view.

Ah that is a different story. Then please post your code for $user, $everyone_in_the_room & $model and how you call them in the view

if(isset($user)){echo ‘YAY!! user worked’;}

if(isset($allUsers)){echo 'YAY!! allUsers worked';}


      if(isset($poll_)){echo 'YAY!! poll worked';}

the poll_ is a typo

I am assuming this is how your view looks like. What I want to see is how your action looks like :)


public function actionCreate()

	{

		$model=new Poll;


		// Uncomment the following line if AJAX validation is needed

		// $this->performAjaxValidation($model);


		if(isset($_POST['Poll']))

		{

                        $user=User::model()->find('username=?', array(Yii::app()->user->name));

                        $everyone_in_the_room = User::model()->findAll('LOWER(room_name)=?', array($user->room_name));

			$model->attributes = $_POST['Poll'];                        

                        $model->room_name = $user->room_name;

                        $model->in_session=1;

                                                

                       

			if($model->save())

                        {                             

                           $this->render('../room/openModeratorRoom',array('Puser'=>$user,'PallUsers'=>$everyone_in_the_room,'Ppoll_'=>$model)); 

                        }

                          

		}                                              


		$this->render('_form',array(

			'model'=>$model,

		));

	}

once again, ignore the Puser, PallUsers typos. they’re named correctly in my code




if(isset($Puser)){echo 'YAY!! user worked';}

if(isset($PallUsers)){echo 'YAY!! allUsers worked';}

if(isset($Ppoll_)){echo 'YAY!! poll worked';}



sorry Flavio, that was a typo on my part before pasting my code, I was trying something. The variable names are the same in both controller and view files I assure you, still no joy. Thanks for your input though guys

try this if show something instead render a view:




if($model->save())

{

if(isset($user)){echo 'YAY!! user worked';}

if(isset($allUsers)){echo 'YAY!! allUsers worked';}

if(isset($poll_)){echo 'YAY!! poll worked';}

}