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   791 Views

Avatar
omarkohl

Community Member, 30 Posts

1 March 2011 at 5:56am

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

Forum Moderator, 1805 Posts

1 March 2011 at 6:10am

how about...

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

Avatar
omarkohl

Community Member, 30 Posts

1 March 2011 at 9:42pm

Works like a charm :-D