Multi Select Lists - Pros And Cons

I have a few attributes in my model that require the ability to select multiple values.

Is there a good way to do this or a bad way I should avoid?

I have seen some references to checkbox lists.

How does this affect the ability to search in CGridView and other screen widgets?

Hi AustinGeek,

I had to do this exact same thing on my web app just the other day, so I thought I’d share with you what worked for me. In my case, I wanted to be able to search my user records for users that were in the cities I selected. The key is knowing that a multiple selection drop down list submits the result as an array.

So, first, I changed the drop down list in my search form to a multiple select list…

echo $form->dropDownList($model, 'city_id', CHtml::listData(City::model()->findAll(array('select'=>'id, title'), 'id', 'title'), array(

	'prompt'=>Yii::t('main', 'All'),




Then, you just need to edit the search() method in your model and change the attribute you’re searching on to an IN condition (rather than a ‘compare’ condition)…

$criteria->addInCondition('city_id', $this->city_id);

And that’s it.

To make it even prettier / user friendly you can dress it up by using ASMselect or ECHmultiselect extensions.

That looks more like a HAS_MANY relation to me; if I was you, I would create a new table for each of such attributes that hold multiple values.

Besides that, solutions from mikewalen and waitforit are correct, although aiming at a different problem.

Thank you all ! Will look into those extensions and play around a bit.