5ome 5ome - 3 months ago 10x
PHP Question

Yii dropdownlist using $form-> dropdownlist

i want to create a form from 2 different models,
1st is for countries, and the 2nd is for documents.
The problem is that i can't make a dropdown list, i get the errors all the time.

Here's the code, first my controller.php part

$model = new Country;
$model2 = new Product;

$this->performAjaxValidation(array($model, $model2));
// populate input data to $model and $model2

// validate BOTH $model and $model2
$valid=$model2->validate() && $valid;

// use false parameter to disable validation

$countriesIssued = Country::model()->findAll(array('select'=>'code, name', 'order'=>'name'));
$this->render('legalisation', array('model'=>$model, 'model2'=>$model2, 'documents'=>$documents, 'countriesIssued'=>$countriesIssued, 'countries'=>$countries, 'flag'=>$flag));

In my view script I use this code

<?php $form = $this->beginWidget('CActiveForm', array(
)); ?>

<?php echo $form->errorSummary(array($model,$model2)); ?>

<?php echo $form->dropDownList($model, 'countriesIssued',
CHtml::listData($countriesIssued, 'code', 'name'));?>

<?php $this->endWidget(); ?>

but i get this error :
Property "Country.countriesIssued" is not defined.

Ok it's not defined, i try to change it to 'countriesIssued', then i got another error saying Invalid argument supplied for foreach() .

If anybody can help me please.
I know there is more solutions on net, i try it but not understand, Thanks.


By definition, the first param of listData is an array; Your is a object;

echo $form->dropDownList($model, 'classification_levels_id', CHtml::listData(ClassificationLevels::model()->findAll(), 'id', 'name'),$classification_levels_options);