Yii Form表单 复选框 Array To String Conversion

写了一个注册表单 里面有一项为“爱好” 是复选框 当我点击提交时出错了

10:40:28.244663 error php

Array to string conversion

(D:\xampp\htdocs\2013819\framework\db\schema\CDbColumnSchema.php:146)

Stack trace:

#0 D:\xampp\htdocs\2013819\framework\db\ar\CActiveRecord.php(795):

User->insert()

#1

D:\xampp\htdocs\2013819\shop\protected\controllers\UserController.php(62):

User->save()

#2 D:\xampp\htdocs\2013819\framework\web\actions\CInlineAction.php(49):

UserController->actionRegister()

#3 D:\xampp\htdocs\2013819\framework\web\CController.php(308):

CInlineAction->runWithParams()

#4 D:\xampp\htdocs\2013819\framework\web\CController.php(286):

UserController->runAction()

#5 D:\xampp\htdocs\2013819\framework\web\CController.php(265):

UserController->runActionWithFilters()

#6 D:\xampp\htdocs\2013819\framework\web\CWebApplication.php(282):

UserController->run()

#7 D:\xampp\htdocs\2013819\framework\web\CWebApplication.php(141):

CWebApplication->runController()

#8 D:\xampp\htdocs\2013819\framework\base\CApplication.php(169):

CWebApplication->processRequest()

#9 D:\xampp\htdocs\2013819\shop\index.php(16): CWebApplication->run()

REQUEST_URI=/2013819/shop/index.php?r=user/register

in D:\xampp\htdocs\2013819\shop\protected\controllers\UserController.php

(62)

in D:\xampp\htdocs\2013819\shop\index.php (16)

usermodel中的rules

public function rules()

{


	// NOTE: you should only define rules for those attributes that


	// will receive user inputs.


	return array(


		array('username, password, user_qq, user_tel', 'required'),


                    array('user_email', 'email'),


                    array('user_sex, user_xueli', 'numerical', 'integerOnly'=>true),


		//array('password, user_qq, user_tel, user_hobby', 'length', 'max'=>32),


		array('user_hobby','required'),


		array('user_introduce', 'safe'),


		


	);


}

usercontroller中的注册方法

function actionRegister(){

    //实例化数据模型对象user


    $user_model = new User();


    /**


     * renderPartial不渲染布局


     * render会渲染布局 


     */


    //$this ->renderPartial('register');


    


    //性别信息


    $sex[1] = "男";


    $sex[2] = "女";


    $sex[3] = "保密";


    


    //定义学历


    $xueli[1] = "-请选择-";


    $xueli[2] = "小学";


    $xueli[3] = "初中";


    $xueli[4] = "高中";


    $xueli[5] = "大学";


    


    //定义爱好信息


    $hobby[1] = "篮球";


    $hobby[2] = "足球";


    $hobby[3] = "排球";


    $hobby[4] = "棒球";


    


    //如果用户有注册表单


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


        //给模型收集表单信息


        //foreach($_POST['User'] as $_k => $_v){


        //    $user_model -> $_k = $_v;


        //}


        


        //上边的foreach,在yii框架里边有优化,使用模型属性attributes来进行优化


        //attributes 属性已经把foreach集成好了,我们可以直接使用


        $user_model -> attributes = $_POST['User'];


        


        //实现信息存储


        if($user_model -> save())


	echo 'success';


            //$this ->redirect ('./index.php');  //重定向到首页


    }


    


    $this -> render('register',array('user_model'=>$user_model,'sex'=>$sex,'xueli'=>$xueli,'hobby'=>$hobby));


}

视图中爱好的hobby的HTML代码

<tr>

<!–checkBoxList($model,$attribute,$data,$htmlOptions=array())–>

<td align=“right”><?php echo $form->label($user_model, ‘user_hobby’); ?></td>

<td><?php echo $form -> checkBoxList($user_model,‘user_hobby’,$hobby,array(‘separator’=>’&nbsp;’)); ?></td>

</tr>

请问我该怎么写这段代码