bitmask3.php

<?php
// http://www.dereuromark.de/2012/02/26/bitmasked-using-bitmasks-in-cakephp/

$this->Comments->Behaviors->attach('Bitmasked', array('mappedField'=>'statuses'));

const STATUS_ACTIVE = 1;
const STATUS_PUBLISHED = 2;
const STATUS_APPROVED = 4;
const STATUS_FLAGGED = 8;

public static function statuses($value = null) {
	$options = array(
		self::STATUS_ACTIVE => __('Active'),
		self::STATUS_PUBLISHED => __('Published'),
		self::STATUS_APPROVED => __('Approved'),
		self::STATUS_FLAGGED => __('Flagged'),
	);
	return parent::enum($value, $options);
}


echo $this->Form->input('statuses', array('options'=>Comment::statuses()), 'multip'e=>'checkbox'));


// Searching for a record
$conditions = array('status' => BitmaskedComment::STATUS_ACTIVE | BitmaskedComment::STATUS_APPROVED);
$comments = $this->Comment->find('first', array('conditions' => $conditions));

// Search for a specific record
$conditions = array('statuses' => array(BitmaskedComment::STATUS_ACTIVE, BitmaskedComment::STATUS_APPROVED));
$comment = $this->Comment->find('first', array('conditions' => $conditions));



?>