YiiBooster
YiiBooster copied to clipboard
dropDownListGroup values from database
Hi Guys, I know that dropDownListGroup can display values as follows
<?php echo $form->dropDownListGroup(
$model,
'Category',
array(
'wrapperHtmlOptions' => array(
'class' => 'col-sm-5',
),
'widgetOptions' => array(
'data' => array('Yacht'=>'Yacht', 'Boat'=>'Boat', 'Ship'=>'Ship', 'Saddleboat'=>'Saddleboat', 'Rubberboat', 'Others'),
'htmlOptions' => array(),
)
)
); ?>
How can I get the values in the 'data' from a database table?
you can use listData function
TbHtml::listData(Category::model()->findAll(),'id','name')
Hi Guys, Love work done here.
One question couldn't find a way to crate a dropDownListGroup passing an empty value as a default as we do with regular Yii form
$form->dropDownList($model, 'id', CHtml::listData($model->findAll(), 'id', 'username'),array('empty' => '--'));
Is there any way to do that with dropDownListGroup ?
Thanks in advance.
MaximilianoRicoTabo:
'htmlOptions' => array('empty'=>''), or
'htmlOptions' => array('prompt'=>'')
Will try. Thank you very much ! El mar 9, 2015 9:02 PM, "cgonza85" [email protected] escribió:
MaximilianoRicoTabo: 'htmlOptions' => array('empty'=>''), or
'htmlOptions' => array('prompt'=>'')
— Reply to this email directly or view it on GitHub https://github.com/clevertech/YiiBooster/issues/932#issuecomment-77970813 .