Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Data Model Questions

[SOLVED] Check if var is correct Enum value


Reply

3 Posts   722 Views

Avatar
omarkohl

1 March 2011 at 5:56am Community Member, 30 Posts

I have a DataObject with this:

public static $db = array(
'Foo' => Enum("A,B,C,D","A")
);

In a method of another DataObject I want to check if a certain $var is a valid Foo. How can I do that?

Avatar
swaiba

1 March 2011 at 6:10am Forum Moderator, 1796 Posts

how about...

if (in_array($var,singleton('YourDataObject')->dbObject('Foo')->EnumValues())) {
//do stuff
}

Avatar
omarkohl

1 March 2011 at 9:42pm Community Member, 30 Posts

Works like a charm :-D