I’ve got 2 tables :
manufacturers (id, name) and devices (id, model, manufacturer).
They are happily connected and everything works fine. I need to create a selectbox and want it to be categorized by manufacturer, don’t know how to set an optgroup for selectbox I’m using :
echo CHtml::dropDownList('input',$sv, CHtml::listData(Devices::model()->findAll(), 'id', 'model'));
what should I paste as a fourth parameter in listData?
madand
(Dev Madand)
January 31, 2012, 10:28pm
2
echo CHtml::dropDownList('input',$sv, CHtml::listData(Devices::model()->findAll(), 'id', 'model', 'manufacturer.name'));
adinugro
(Adinugro)
January 31, 2012, 10:34pm
3
Hi,
How the manufacturers related to the devices?
What I ever did is
product
-------
id
name
unit
categoryFk FK to category(id)
status
category
--------
id
name
status
in product, I have relation to the category by
'category' => array(self::BELONGS_TO, 'Category', 'categoryFk'),
Below is my listData,
$activeProducts = CHtml::listData(Product::model()->with('category')->findAll(array('select' => 't.id, t.name, category.name', 'condition' => 't.status = :status', 'params' => array(':status' => 1), 'order' => 't.name')), 'id', 'name', 'category.name'); ?>
Hope this can help