Yii Framework Forum: nested dropDownList with optiongroup - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

nested dropDownList with optiongroup Rate Topic: -----

#1 User is offline   Lennier 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 12-June 12

Posted 13 June 2012 - 10:13 AM

Hi folks,

i started to learn yii a few days ago and i'm stuck with the following problem for hours...

I want to generate a dropDownList like

<div class="cars-select">
    <?php echo CHtml::dropDownList('Cars', 'car_id', array(
        'Mazda'=>array(
            'mazda-rx7'=>'RX7',
            'mazda-rx5'=>'RX5',
        ),
        'Volvo'=>array(
            'volvo-b9tl'=>'B9TL',
            'volvo-l90e-radlader'=>'L90E Radlader',
        ),
    )); ?>
</div>


from http://www.yiiframew...mple-chtml/#hh4

But i get the data from the Database with following table-structure:

Table Studycourse:
id, coursename, extension_of

1, Law, 0
2, Economics, 0
3, Business Law, 1
4, Macro Economics, 2


My DropDownList without option group is working:

$courseExt = Studycourse::model()->findAll("extension_of IS NOT NULL", array('order' => 'id'));
echo $form->dropDownList($model, 'studycourse_id', GxHtml::listDataEx($courseExt));

But how can i populate a dropdownlist with option groups?

It should generate the following html:

<select name="studycourse" id="course">
        <optgroup label="Law">
            <option value="law-business">Business Law</option>
        </optgroup>
        <optgroup label="Economics">
            <option value="economics-macro">Macro Economics</option>
        </optgroup>
</select>

0

#2 User is offline   ikizmert 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 01-July 11

Posted 19 March 2013 - 03:44 PM

upppp
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users