lundi 30 novembre 2015

How to mark checkbox as selected using Bitwise in CakePHP?

I am developing an application in CakePHP 2.6 and I have a form where a user can set a series of flags when creating a calendar event.

I have managed to set up the 'add' action to display the flags and to also loop through in the controller after validation and save the value into my table. This process is done using bitwise. Code example below:

'add' action view:

echo $this->Form->input('flag', array('label' => false, 'type' => 'select', 'multiple' => 'checkbox', 'options' => $flagtypes, 'hiddenField' => false));

'add' action controller:

$flags = 0;
foreach ($data['flag'] as $r) {
    $flags |= (int)$r;
}

I am however having trouble getting the checkboxes for the flags to be marked as selected in the edit action view when they are displayed.

'edit' action view:

echo $this->Form->input('flag', array('label' => false, 'type' => 'select', 'multiple' => 'checkbox', 'options' => $flagtypes, 'hiddenField' => false, 'checked' => $results[0]['BitwiseFlag']));

$results[0]['BitwiseFlag'] = 32 in the table.

$flagtypes array:

array(2) { [32]=> string(4) "Test" [64]=> string(9) "Testing 2" }




Aucun commentaire:

Enregistrer un commentaire