I am trying to use drop down list widget :
$this->widget('ext.multiselect.JMultiSelect',array(
'model'=>$model,
'attribute'=>'attribute',
'data'=>$data,
// additional javascript options for the MultiSelect plugin
'options'=>array()
));
What I want to know is that Details of each option available in the widget array Like what is ‘attribute’ , ‘model’ and’data’ represent , as I an unable to understand it form the documentation.
The
modelparam is the model you are creating the multi select for.The
attributeis the model attribute you are creating the multi select for.The
datais an array of key/value pairs for the list items you want to display in the multi select.For example, if you had a model ‘User’ and in that model you had a field ‘access_rights’ and you wanted to have that field as a multi select box with a few values, you might do something like:
In your controller:
In your form in your view file:
Edit:
To add data to the multi select options from another model you can use the CHtml::listData() method, this takes an active record result set and converts it into an array of key/value pairs so you can use in any of the other CHtml methods that require a key/value pair. To do this you simply get the records you’re after from the database using active record, eg;
You can then put that into the listData() method and it’ll create your array:
(where ‘id’ and ‘name’ are the fields from the model table that you want to be the ‘key’ and ‘value’ within the array)