I’m really newbie in using yii framework … so i need help …
i have this code in my _form.php which is a checkboxlist
<td><?php echo $form->labelEx($model,'visit_purpose'); ?></td>
<td><?php echo $form->checkBoxList($model,'visit_purpose',
array(
'ASQ administration'=>'ASQ administration',
'IFSP'=>'IFSP'),
array('labelOptions'=>array('style'=>'display:inline'),'separator'=>" | ")); ?></td>
<td><?php echo $form->error($model,'visit_purpose'); ?></td>
and this one in my model.php … i got this code in one of the threads here in forum
public $purposeIds;
public function afterFind()
{
parent::afterFind();
$this->purposeIds = CJSON::decode($this->visit_purpose);
$this->purposeIds = CJSON::decode($this->presents);
$this->purposeIds = CJSON::decode($this->concern_for_cg);
$this->purposeIds = CJSON::decode($this->pb_physical_condition_concern);
if (!is_array($this->visit_purpose) || !is_array($this->presents) || !is_array($this->concern_for_cg) || !is_array($this->pb_physical_condition_concern))
{
$this->purposeIds[] = array('selected'=>'selected');
}
$this->purposeIds = array();
if (sizeof($this->purposeIds)){
foreach ($this->visit_purpose as $visit_purpose){
$this->purposeIds[]=array();
}
}
if (sizeof($this->purposeIds)){
foreach ($this->presents as $presents){
$this->purposeIds[]=array();
}
}
if (sizeof($this->purposeIds)){
foreach ($this->concern_for_cg as $concern_for_cg){
$this->purposeIds[]=array();
}
}
if (sizeof($this->purposeIds)){
foreach ($this->pb_physical_condition_concern as $pb_physical_condition_concern){
$this->purposeIds[]=array();
}
}
}
protected function beforeValidate()
{
if (!is_array($this->visit_purpose)){
$this->purposeIds = array();
}
if (!is_array($this->presents)){
$this->purposeIds = array();
}
if (!is_array($this->concern_for_cg)){
$this->purposeIds = array();
}
if (!is_array($this->pb_physical_condition_concern)){
$this->purposeIds = array();
}
$this->visit_purpose = CJSON::encode($this->visit_purpose);
$this->presents = CJSON::encode($this->presents);
$this->concern_for_cg = CJSON::encode($this->concern_for_cg);
$this->pb_physical_condition_concern = CJSON::encode($this->pb_physical_condition_concern);
return parent::beforeValidate();
}
it saves in the database like it should but the output is like this … [“ASQ administration”,“IFSP”] … well obviously … i need to remove [""] and let it be a comma separated array … how can i fix this … is there something wrong with the code i’m using … if yes … please do help me the proper way in saving checkboxlist array thank you so very much