Enum for my entities


#1

so I has a User class that has status field. its either: 0->unconfirmed, 1->active, etc.

how do I do this using this approach:
AppController
public static function enum($value, $options, $default = '') { if ($value !== null) { if (array_key_exists($value, $options)) { return $options[$value]; } return $default; } return $options; }

User Entity
’public static function statuses($value = null) {
$options = array(
self::STATUS_UNCONFIRMED => __(‘statusUnconfirmed’, true),
self::STATUS_ACTIVE => __(‘statusActive’, true),
self::STATUS_INACTIVE => __(‘statusInactive’, true),
);
return parent::enum($value, $options);
}
const STATUS_UNCONFIRMED = 0;
const STATUS_ACTIVE = 1;
const STATUS_INACTIVE = 2;’

and access in views:
echo $this->Form->input(‘status’, array(‘options’ => User::statuses()));


#2

So what’s the problem? Looks like your code should be working.