Hi
I added support for enum in Form Helper magic field.
It's creating select field by default, but 'radio' type will work too.
The patch fits cakePHP 2.0.6, but I think it is very ease to apply the
changes to other versions.
Tamar Klein
Atar + Plus
--
Our newest site for the community: CakePHP Video Tutorials
http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others
with their CakePHP related questions.
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php
--- FormHelper.php 2012-02-15 00:32:56.674417720 +0200
+++ cakephp/lib/Cake/View/Helper/FormHelper.php 2012-02-15 09:49:45.768793621 +0200
@@ -954,6 +954,15 @@
$modelKey = $this->model();
$fieldKey = $this->field();
+ $fieldDef = $this->_introspectModel($modelKey, 'fields', $fieldKey);
+
+ $enum_values=array();
+ if(preg_match('/^enum\((.*)\)$/',$fieldDef['type'],$enum_values)) {
+ if(!isset($options['options'])) {
+ $options['options'] = preg_split('/,/',preg_replace('/\'/','',$enum_values[1]));
+ $options['options'] = array_combine($options['options'],$options['options']);
+ }
+ }
if (!isset($options['type'])) {
$magicType = true;
@@ -964,7 +973,7 @@
$options['type'] = 'password';
} elseif (isset($options['checked'])) {
$options['type'] = 'checkbox';
- } elseif ($fieldDef = $this->_introspectModel($modelKey, 'fields', $fieldKey)) {
+ } elseif ($fieldDef) {
$type = $fieldDef['type'];
$primaryKey = $this->fieldset[$modelKey]['key'];
}
@@ -998,6 +1007,10 @@
$options['type'] = 'select';
}
+ if (preg_match('/^enum\(/',$fieldDef['type'])) {
+ $options['type'] = 'select';
+ }
+
if ($modelKey === $fieldKey) {
$options['type'] = 'select';
if (!isset($options['multiple'])) {