habatone
(Derekhabington)
March 21, 2012, 8:36pm
1
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));
bettor
(Live Webscore)
March 21, 2012, 9:35pm
2
try
$this->render('openModeratorRoom',array('user'=>$user,'allUsers'=>$everyone_in_the_room,'poll'=>$model));
habatone
(Derekhabington)
March 21, 2012, 9:37pm
3
tried that, I get an error saying it can’t find the view file. Thanks though
bettor
(Live Webscore)
March 21, 2012, 9:39pm
4
ok you need to make sure that you have the view file. Where is the file named openModeratorRoom.php located
habatone
(Derekhabington)
March 21, 2012, 9:45pm
5
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.
bettor
(Live Webscore)
March 21, 2012, 9:48pm
6
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
habatone
(Derekhabington)
March 21, 2012, 9:58pm
7
if(isset($user)){echo ‘YAY!! user worked’;}
if(isset($allUsers)){echo 'YAY!! allUsers worked';}
if(isset($poll_)){echo 'YAY!! poll worked';}
bettor
(Live Webscore)
March 21, 2012, 10:03pm
9
I am assuming this is how your view looks like. What I want to see is how your action looks like
habatone
(Derekhabington)
March 21, 2012, 10:08pm
10
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,
));
}
habatone
(Derekhabington)
March 21, 2012, 10:10pm
11
once again, ignore the Puser, PallUsers typos. they’re named correctly in my code
Flavio
(Flavioleonelferreira)
March 21, 2012, 10:12pm
12
if(isset($Puser)){echo 'YAY!! user worked';}
if(isset($PallUsers)){echo 'YAY!! allUsers worked';}
if(isset($Ppoll_)){echo 'YAY!! poll worked';}
habatone
(Derekhabington)
March 21, 2012, 10:15pm
13
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
Flavio
(Flavioleonelferreira)
March 21, 2012, 10:55pm
14
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';}
}