This is a comment that I would have posted on this blog entry, if the author was willing to receive it without me signing up. It’s about retrieving the keys and values of an enum field in CakePHP:
This version returns the original mysql key values and returns false if the enum is not found:
function generateEnumArray($enum)
{
if (!is_string($enum)) {
return false;
}
foreach($this->_tableInfo->value as $field)
{
// found matching field, check for type enum and field name
if(substr($field['type'], 0 ,4) == 'enum' && $field['name'] == $enum)
{
$enum_array = array();
foreach(split("','", substr($field['type'], 6, -2)) as $key => $value)
{
$enum_array[$key]=$value;
}
return $enum_array;
}
}
// enum not found
return false;
}
This entry was posted
on Monday, December 18th, 2006 at 11:23 am and is filed under cakephp, comments, nerdnotes.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.
www.hiddenspiral.net/node/23
This is a comment that I would have posted on this blog entry, if the author was willing to receive it without me signing up. It’s about retrieving the keys and values of an enum field in CakePHP:
This entry was posted on Monday, December 18th, 2006 at 11:23 am and is filed under cakephp, comments, nerdnotes. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.