hii all,

  I have a Problem when creating dropDownList in form. my code is ::

<?php echo $form->labelEx($model,'company_id'); ?>

<?php echo $form->dropDownList($model,'company_id',CHtml::listData(CompanyDetail::model()->findall(),'company_id','company_name'),array('prompt'=>'Select Company')); ?>

<?php echo $form->error($model,'company_id'); ?>

when i write this code then from that field nothing to display.

thaks in advance,

jalpa patel

Are you sure that


returns data?

company_id and company_name fields exist in CompanyDetail?

Ya sure

What display

var_dump( CHtml::listData(CompanyDetail::model()->findall(),'company_id','company_name') )

when we use var_dump then from company name nothing to display

So you have an error in field names or data returned from findAll().

even if there no records in the database, it should still display a select box with an empty prompt

// you could replace your code with this just to debug

<?php echo $form->labelEx($model,'company_id'); ?>

<?php $options = array('company1', 'company2'); ?>

<?php echo $form->dropDownList($model, 'company_id', $options, array('prompt'=>'Select Company')); ?>

<?php echo $form->error($model,'company_id'); ?>

Sorry to hijack the thread but would you happen to know what the difference is between "prompt" and "empty"? They seem to function the same when strings are passed, but "empty" also accepts key=>value arrays with options that do not get selected when an existing key value is passed.