I got a problem with getting multiple values for checkboxes from a column in database.
In my database i got a value of '9,10' in a column
However, in the edit view i only got 9, which mean only the checkbox with the value 9 is checked.
How can i make sure that checkbox for value 9 and 10 is both checked in the edit view
I think I need to explode the value of 9,10. but i don't know how can i do it.
Controller
<?php $categories = $this->Product->Category->find('list',array('conditions' =>
array('parent_id !=' => 0),'order' => array('Category.name ASC')));
$this->set(compact('subcategories'));
?>
View (admin_edit)
<?php
echo $form->create('Product', array('action' =>
'edit','class'=>'cmxform','id'=>'form2','type' => 'file'));
echo $form->input('category_id', array('multiple' => 'checkbox', 'label' =>
false,'validate'=>'required:true','options'=>$categories));
echo $form->end('Save',array('class' => 'btn'));
?>
You can explode it in the model afterFind() callback: http://book.cakephp.org/2.0/en/models/callback-methods.html#afterfind