在Yii中制作的表单返回错误,属性未定义


Form made in Yii returns error, Property is not defined

我有控制器ecommerceccontroller .php它看起来像这样:

public function actionLegalisation()
    {
        $model = new Product();
$this->render('legalisation', array('model'=>$model, 'documents'=>$documents, 'countriesIssued'=>$countriesIssued, 'countries'=>$countries, 'flag'=>$flag));
    }

在Legalisation视图中我有:

<?php $form=$this->beginWidget('CActiveForm', array(
    'id'=>'legalisationForm',
    'action' => $this->createUrl($this->id."/".$this->action->id),
    'enableAjaxValidation'=>true,
    'clientOptions' => array(
  'validateOnSubmit'=>true,
  'validateOnChange'=>true,
  'validateOnType'=>false,
     ),
)); ?>
    <table>
        <tr>
            <td>
                <?php echo $form->dropDownList($model, 'countriesIssued', $select = array($_POST['countriesIssued'])); ?>
            </td>
        </tr>
    </table>

这段代码返回一个异常属性"Product "。未定义"已发布国家"。

当我使用html做所有这些事情时,一切都很好,并且得到了一个下拉列表,其中包含国家名称,如下所示:

<?php echo CHtml::dropDownList($form, 'countriesIssued', $select = array($_POST['countriesIssued']),
                  CHtml::listData($countriesIssued, 'code', 'name')); ?>

我需要下拉列表字段值(国家)有人能帮助我吗?谢谢。

下面的代码将帮助您克服所面临的错误。

将此写入控制器

    $criteria = new CDbCriteria;
    $criteria->order = 'country_name ASC';
    $locations = Countries::model()->findAll($criteria);
    $dataAry['countries'] = CHtml::listData($locations, 'id', 'country_name');
    $this->render('index', $dataAry);

将此写入您的表单

    echo $form->dropDownList($model, 'attribute', $countries, array('prompt' => 'Select Country'));
    echo $form->error($model, 'attribute');

更多信息请访问http://www.yiiframework.com/forum/index.php/topic/9693-cactiveform-dropdownlist-selectedselected/