我是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'); ?>                
<?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',
);
}
帮帮我..
答案 0 :(得分:1)
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() ); ?>