I saw the API about CHtml,it’s can generate activeDropDownList & dropDownList,but i want a select list with optgroup,how can i do this?
Thanks!
I saw the API about CHtml,it’s can generate activeDropDownList & dropDownList,but i want a select list with optgroup,how can i do this?
Thanks!
solved by myself,haha…
in the model,i have a function to get category:
public function getCategoryOptions()
{
return array(
array('id'=>256,'text'=>'TV','group'=>'Electrical'),
array('id'=>257,'text'=>'Radio','group'=>'Electrical'),
);
}
in the _form:
<?php $data = CHtml::listData($model->getCategoryOptions(),'id','text','group'); ?>
<?php echo CHtml::activeDropDownList($model,'category',$data); ?>
it’s work.
I love Yii!
Sorry for my English (I’m from Kazakhstan), but how can I use this code with data from database (in getCategoryOptions())?
just what I need, thanks
Hi,
Why not do :
$list = CHtml::listData($model, $valueField, $textField, $groupField)
I think Yii supports many util functions for this .
Thanks
why is this under "Portuguese" forum ??
thanks! you save my time
Yes, it works after changing ‘categoly’ to one of the field names in database table. However, we need nested two levels of optgroup. Could anyone help?
Thanks,
Tak
Hello my People.
For example, We Have same part in our project, but one difference exist.
Check our part of project
in _form
<div class="row">
<?php echo $form->labelEx($model,'autoservicetypedetail_id'); ?>
<?php $urCriteria = array('select'=>'id, name_'.Yii::app()->language);?>
<?php $data = CHtml::listData($model->getCategoryOptions(),'id','text','group'); ?>
<?php echo CHtml::activeDropDownList($model,'autoservicetypedetail_id',$data); ?>
<?php echo $form->error($model,'autoservicetypedetail_id'); ?>
</div>
in model
public function getCategoryOptions()
{
$asts = Autoservicetypedetail::model()->findAll();
$arr = array();
foreach ($asts as $ast) :
$astd = Autoservicetype::model()->findByPk($ast['autoservicetype_id']);
$arr[] = array('id'=>$ast['id'],'text'=>$ast['slug'],'group'=>$astd['slug']);
endforeach;
return $arr;
}
[size="4"]Best Regards Web Studio: www.iSystems.am Official Russia, Armenia[/size]