php - Yii active dropdownlist with optgroup -
i seek create dropdown-list yii, using listdata , activedropdownlist.
i utilize examples found on web, refuses create optgroups me.
$data = chtml::listdata(mymodel::model()->getentries(0), 'id', 'text', 'group');
generates array expected:
array([group1] => array([10]=>firstentry, [20]=>secondentry), [group2]=>array([30]=>firstentrygroup2, [40]=>firstentrygroup2))
and on. it's associative array filled sub-arrays...
but when use
echo chtml::activedropdownlist($model, 'dropdownname', $data);
all flat dropdown without optgroups. entries sub-arrays...
yii 1.1.6 (i read safe-attributes , tried implement it, no success...
the old reply below incorrect. sorry. create optgroups using 'group' attribute in drop downwards info array.
array( array('id'=>256,'text'=>'tv','group'=>'electrical'), array('id'=>257,'text'=>'radio','group'=>'electrical'), );
http://www.yiiframework.com/forum/index.php/topic/6903-how-can-i-generate-a-select-list-with-optgroup/
old answer:
there great gist here shows how create you're after: https://gist.github.com/standardnerd/2909111
<?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', ), )); ?>
you're using activedropdownlist should different because add together $model variable instead of 'cars' , tweak function
php yii drop-down-menu
No comments:
Post a Comment