How To Show String Field Seperated By Semicolone In Checkboxlist And Make Theme Checked


I have tow models : Mailconfig and Courses . I want to show All courses but user courses whitch are saved in Mailconfig

be checked .

user courses are saved in format of (1,2,3,…) in courseids field in Mailconfig model

courses are save with fields of id, name in Courses model, I have no problem with loading the items. but what ever I do only one item is checked at last.

I have done a lot of search and tested deferent ways but none of theme worked for me. I dont know where the problem is

I also saved user courses in seperate records but that didnt work too.

This is My controller action

    public function actionMailconfig() {

       $userid = is_null($userid) ? Yii::app()->user->id : $userid;

       $criteria = new CDbCriteria ();

       $criteria->condition = "userid=".$userid;

       $model = Mailconfig::model()->find($criteria);

       if (isset($_POST['Mailconfig'])) {

            $model->attributes = $_POST['Mailconfig'];

            if ($model->validate())

                if ($model->save()) {

                    Yii::app()->user->setFlash('success', "ok");




        $this->render('mailconfig', array(

            'model' => $model,



In My form

    echo $form->checkBoxList($model,'courseids',CHtml::listData(Courses::model()->findAll(),'id','name'));

// my previous way :

              echo $form->checkBoxList($model,'courseids',$model->getCoursesOptions(),

                array('multiple' => 'true', 'separator' => '<br>', 'labelOptions' => array('size' => 40, 'maxlength' => 40, 'style' => 'display:inline'))

in model Mailconfig

    public function getCoursesOptions() {

        $corseCodes = Courses::Model()->findAll(array('condition' => 'active=1'));

        $corseCodesList = CHtml::listData($corseCodes, 'id', 'name');

        return $corseCodesList;


Thanks for any help.

This Thread helped me

  [url=&quot;;]Checkboxlist Checked On Update Time How to get checked checkboxlist update time[/url]