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;
}
www.hiddenspiral.net/node/23
Monday, December 18th, 2006This 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:
Posted in cakephp, comments, nerdnotes | No Comments »