title: How to mark checkbox as selected using Bitwise in CakePHP?
body: <p>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.</p>
  
  <p>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:</p>
  
  <p>'add' action view:</p>
  
  <p><code>echo $this-&gt;Form-&gt;input('flag', array('label' =&gt; false, 'type' =&gt; 'select', 'multiple' =&gt; 'checkbox', 'options' =&gt; $flagtypes, 'hiddenField' =&gt; false));</code></p>
  
  <p>'add' action controller:</p>
  
  <pre><code>$flags = 0;
  foreach ($data['flag'] as $r) {
      $flags |= (int)$r;
  }
  </code></pre>
  
  <p><strong>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.</strong></p>
  
  <p>'edit' action view:</p>
  
  <pre><code>$selected = array($results[0]['BitwiseFlag']);
  echo $this-&gt;Form-&gt;input('flag', array('label' =&gt; false, 'type' =&gt; 'select', 'multiple' =&gt; 'checkbox', 'options' =&gt; $flagtypes, 'hiddenField' =&gt; false, 'selected' =&gt; $selected));
  </code></pre>
  
  <p>$results[0]['BitwiseFlag'] = 32 in the table.</p>
  
  <p>$flagtypes array:</p>
  
  <p><code>array(2) { [32]=&gt; string(4) "Test" [64]=&gt; string(9) "Testing 2" }</code></p>