Push Data To View

I am having a really strange problem. I am trying to send a variable to a view (a file name - for purpose of testing I just set the variable $nf to a string value). In the controller I have e.g.




public function actionCreate()

	{

        $model=new NewTask;

	$nf = "test";

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

		{

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

			$model->file_name=CUploadedFile::getInstance($model,'file_name');

			if($model->save())

			{

				$model->file_name->saveAs($dir.'/'.$model->file_name->name);

				$this->redirect(array('view','id'=>$model->id, 'nf'=>$nf,));

			}

		}




Then in the view I simply use




<h4>File successfully uploaded - <?php echo $nf; ?>

//This generates an error - Undefined variable nf

//However I can use Get

<h4>File successfully uploaded - <?php echo $_GET['nf']; ?>



I can pass the variable and use GET to retrieve the value however I should not have to do that. In the sample code above I have just set the variable to a string however it will be used to pass the file name to the view - I just changed it to a string for testing and still I get an undefined variable error. Any help appreciated.





$this->redirect(array('view','id'=>$model->id, 'nf'=>$nf,));


// to 

$this->render('view',array('id'=>$model->id, 'nf'=>$nf,));

Yii::app()->end();






you can refer the $id and $nf if use render .

if use redirect you will have to use $_GET[‘xx’] to refer them . :lol:

redirect will use "header" php function , you can view the source

I remember reading that - thanks that is the solution. Much appreciated