Undefined variable: status

hello everyone… :rolleyes:

i have this action:


	public function actionIndex()

	{

		$dataProvider=new CActiveDataProvider('Biodata');

		$test = Status::model()->findall();

		$stat = array();

		foreach ($test as $tes)

		{

			$stat[$tes['id']] = $tes['status'];

		}

		

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

			'stat'=>$stat,

			'test1'=>"hello world",

			'dataProvider'=>$dataProvider

		));

		

	}

when i want to call the "stat" from _view.php like this:


	<b><?php echo CHtml::encode($data->getAttributeLabel('status')); ?>:</b>

		<?php echo CHtml::encode($data->status); ?>

		<?php echo $stat[$data->status]; ?>

then i got error "undefined variable :stat "…

even i want just call the $test1, i got error like the above too…

i don’t know what to do, please help me… :huh:

You would access those variables as if they were normal variables. So if you echo the $test variable, you would see "hello world".

http://www.yiiframework.com/doc/guide/1.1/en/basics.view

thank you for your answer masters… :rolleyes:

but i think, i miss the point…

what i mean is, how to pass variables to the _view.php??

i do not really understand what the guide say about views…

i just want to "send" the $test variable to _view.php so i can show the content of $test in the page, with this code (BiodataController.php):


		$test= "hello world";

		$dataProvider=new CActiveDataProvider('Biodata');

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

			'test'=>$test,

			'dataProvider'=>$dataProvider,

		));

and this is what i write in _view.php to pull the content of $test out:


<b><?php echo CHtml::encode($data->getAttributeLabel('id_status')); ?>:</b>

	<?php echo CHtml::encode($data->id_status); ?>

	<?php echo $test; ?>

	<br />



but that code return me an error "Undefined variable: test"…

what’s the solution??

thanks… :lol:

you are sending the variable to ‘index’, you have to then send it from ‘index’ to ‘_view’ i.e.:




<?php echo $this->renderPartial('_view', array('model'=>$model. 'test'=>$test)); ?>



1 Like

thank’s for the solutions, that’s work… :lol: