clevertech / YiiBooster

YiiBooster
BSD 2-Clause "Simplified" License
544 stars 305 forks source link

dropDownListGroup values from database #932

Open sachy123 opened 10 years ago

sachy123 commented 10 years ago

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?

peterfromearth commented 10 years ago

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

MaximilianoRicoTabo commented 9 years ago

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.

cgonza85 commented 9 years ago

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

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

MaximilianoRicoTabo commented 9 years ago

Will try. Thank you very much ! El mar 9, 2015 9:02 PM, "cgonza85" notifications@github.com 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 .