类createProduct的对象无法转换为yii中的字符串错误



我是yii的新手,我正在努力创建下拉。

    <?php
/* @var $this CreateproductController */
/* @var $model Createproduct */
/* @var $form CActiveForm */
?>
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
    'id'=>'createproduct-form',
    'method'=>'post',
    // Please note: When you enable ajax validation, make sure the corresponding
    // controller action is handling ajax validation correctly.
    // There is a call to performAjaxValidation() commented in generated controller code.
    // See class documentation of CActiveForm for details on this.E0E0E0 EFF0F2
    'enableAjaxValidation'=>false,
)); ?>
    <?php echo $form->errorSummary($model); ?>

    <div class="row" style="background-color: #F7F7F7; height:30px;">
        <?php echo $form->labelEx($model,'Product Type'); ?>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
        <?php echo CHtml::dropDownList($model,'pr_name',$model->getTypeOptions() ); ?>
        <?php echo $form->error($model,'pr_type'); ?>
    </div>
    <div class="row buttons">
        <?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save',array('class'=>'button1')); ?>
    </div>
<?php $this->endWidget(); ?>
</div>

getTypeoptions()方法在该方法内有以下且常数使用,并声明为

const CAT_EMPTY=0;
const CAT_PHONE=1;
const CAT_ROUTERS=2;
const CAT_ACCESSORIES=3;
const CAT_SERVICES=4;
public function getTypeOptions()
{
    return array(
    self::CAT_EMPTY=>'Select_Category',
    self::CAT_PHONE=>'Phones',
    self::CAT_ROUTERS=>'Routers',
    self::CAT_ACCESSORIES=>'Accessories',
    self::CAT_SERVICES=>'Services',

    );
}

帮助我..

CHtml::dropDownList使用中的问题您应该这样使用:

 <?php echo CHtml::dropDownList("model_name[pr_name]",'selected_value',$model->getTypeOptions() ); ?>

另外,您可以使用$form小部件dropDownList功能

<?php echo $form->dropDownList($model, 'pr_name',$model->getTypeOptions() ); ?>

最新更新