Cakephp 2.4 Auto Load Checked values for HABTM

140 views Asked by At

I cannot get the values to auto check. The list of options displays fine.

$this->data['Business']['ExpertiseType'] has values.

Business habtm ExpertiseType defined in all three models still set to their default bake.

Business belongsTo FormEoiEntry

$this->data = $this->FormEoiEntry->find('first', ['conditions'=>['FormEoiEntry.id'=>1324], 'recursive'=>2]);


$this->Form->create('FormEoiEntry');
$this->Form->input('Business.ExpertiseType', ['multiple'=>'checkbox']);
$this->Form->end();

Am I missing something here? I cannot figure out why it is not being detected and checking the boxes.

1

There are 1 answers

4
Anil kumar On

set expertise_types from your controller like this.

$this->set('expertise_types', $this->FormEoiEntry->find('first', [
    'conditions'=>['FormEoiEntry.id'=>1324], 
    'recursive'=>2,
]);

and in your view

$this->Form->input('Business.ExpertiseType', [
    'options' => $expertise_types,
    'multiple'=>'checkbox'
]);

update

In that case pass the selected options values to the $this->request->data['Business']['ExpertiseType']

just like this

$this->request->data['Business']['ExpertiseType'] = array(
    'select option value 1', // you can put your option values
    'select option value 2',
    'select option value 3',
    'select option value 4',
);