Yii framework multiselect dropdown


view/_form

$location_list=MtLocation::model()->findAll(array('order'=>'created_on'));
$location_list_arr=CHtml::listData($location_list,'mt_location_id','location_name');

echo CHtml::dropDownList('MtGetintouch[mt_location_id][]', explode(",",$model->mt_location_id), $location_list_arr,array('empty'=>'Select Locaction Name','multiple'=>'multiple'));

Getintouch Controller
Both in actionUpdate / actionCreate methods

$_POST['MtGetintouch']['mt_location_id'] = implode(",",$_POST['MtGetintouch']['mt_location_id']);

Display Comma Separated locations value in Gridview

public function getLocations($id)
{
$ids= explode(",",$id);
foreach($ids as $key=>$val){
$ids[$key]=(int)$val;
}
$data = Yii::app()->db->createCommand()->select ('GROUP_CONCAT(location_name) as locations')->from('mt_location')->where(array('in','mt_location_id',$ids))->queryRow();
return $data["locations"];

}

Advertisements

2 thoughts on “Yii framework multiselect dropdown

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s