I have this problem, I need to pass multiple values from controller to view (form)
for example following is my action
public function actionCreate()
{
$model=new ProductCondition;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['ProductCondition']))
{
$model->attributes=$_POST['ProductCondition'];
if($model->save())
$this->redirect(array('view','id'=>$model->id));
}
$productCategories = CHtml::listData(ProductCategory::model()->findAll(), 'id','name');
[b]$model->productCatList = $productCategories;[/b]
$this->render('create',array(
'model'=>$model,
[b]'catList'=>$model->productCatList,[/b]
));
}
Here I’m passing ‘model’ and ‘catList’ just to verify I pass catList as a member property of the model as well.
In the view which is a form to create new object.
<div class="row">
<?php echo $form->labelEx($model,'productCategory'); ?>
[b]<?php echo $form->listBox($model, 'productCategory', $catList, array('multiple'=>"multiple")); ?>[/b]
<?php echo $form->error($model,'productCategory'); ?>
</div>
Here it throws an exception saying "Invalid argument supplied for foreach()" which is that $catList is null,
but if I replace $catList with following
<?php echo $form->listBox($model, ‘productCategory’, $model->productCatList, array(‘multiple’=>“multiple”));
Then I can see listbox and the page with items? Why cannot access the $catList directly, is form views support only one varaible from controller to view? What am I missing here, Please help.