YiiBooster icon indicating copy to clipboard operation
YiiBooster copied to clipboard

dropDownListGroup values from database

Open sachy123 opened this issue 11 years ago • 4 comments
trafficstars

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?

sachy123 avatar Aug 28 '14 19:08 sachy123

you can use listData function TbHtml::listData(Category::model()->findAll(),'id','name')

peterfromearth avatar Aug 28 '14 20:08 peterfromearth

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 avatar Mar 09 '15 12:03 MaximilianoRicoTabo

MaximilianoRicoTabo: 'htmlOptions' => array('empty'=>''), or

'htmlOptions' => array('prompt'=>'')

cgonza85 avatar Mar 10 '15 00:03 cgonza85

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 .

MaximilianoRicoTabo avatar Mar 10 '15 10:03 MaximilianoRicoTabo