can anybody help me how to create drop down list in yii all view files?
Hi
<?CHtml::dropDownList($model,'coupon_id', CHtml::listData(Coupon::model()->findAll("user_id=$model->user_id"),'id','title')); ?>
i have to fetch distinct of data from database
Tiny correction; you’ll need to use <?= or <? echo to output the drop down list.
where i need to add this code? i am new to yii…, plz help me
in your view file
i hacve added in view/dataform.php like
<div class="row">
<?php echo $form->labelEx($model,'tier'); ?>
<?php echo CHtml::dropDownList($model,'tier', CHtml::listData(Coupon::model()->findAll("tier=$model->tier"),'AssetID','title')); ?>
<!--<?php echo $form->;dropDownList($model,'tier', CHtml::listData(Tier::model()->findAll(), 'AssetID', 'tier'), array('empty'=>;'--please select--')); ?>-->
<?php echo $form->error($model,'tier'); ?>
</div>
still getting text box only…, do i need to add extra code in datacontroller.php??in actionCreate()
You should be using the $form->dropDownList() method in your case. Why do you have a $form->dropDownList() call commented out in your HTML, along with random semicolons?
plz explain in detail
try this
$list = CHtml::listData(ModelName::model()->findAll(array('group'=>'field u want to be distinct')), 'save_field', 'display_field');
$form=$this->beginWidget('CActiveForm');
echo $form->dropDownList($model,'save_field', $list);
$this->endWidget();
Model will b Ur Model Name from which U want to Fetch Data
save_field is that field which u want to save value of
display_field is that field to display to User in dropdown