I need to store the id of the selected hobbies from my check box in database. First, in my Hobbies table, i view all the hobby names and display it in check box. Now, whichever the hobbies selected, it stores the id of the hobbies in another table.
This is my code in views/sample/register.php
<div class="row">
<?php echo $form->labelEx($model,'hobby');
$opts = CHtml::listData(Hobbies::model()->findAll(),'hobby_id','hobby_name');
echo $form->checkBoxList($model,'hobby',$opts, array('labelOptions'=>array('style'=>'display:inline'),'separator'=>' '));
echo $form->error($model,'hobby'); ?>
</div>
And this is my code in controllers/SampleController.php
if($model->validate())
{
$model->hobby = implode(",",$model->hobby);
if($model->save())
{
$this->redirect(array('site/login'));
}
return;
}
But it displays an error as PHP warning mb_strlen() expects parameter 1 to be string, array given. Please anybody help.