I've been researching a bit and I found that CakePHP's form helper doesn't interpret ENUM fields correctly, so it simply outputs a text input. I found a post that suggested to use a helper for that specific purpose. Does anybody know a better way to achieve this? Or if CakePHP devs intend to correct this some day?
Thanks for reading!
Cake attempts to be database agnostic and therefore this issue won't be "corrected" since it's not a bug. For example, SQL server doesn't have an exact equivalent of MySQL's ENUM field type.
I would recommend getting your possible list of enum values like so:
YourController.php
Then use a
select
field in your view and pass the enums as options. Your current value you'll already have. How does that sound?I created a function that goes into AppController to handle this. I combined some of the information provided above.
Usage:
Function that I put in AppController:
i think the Behaviour way it's good...but the array keys are integer
so i have modified the function like this
}
in order to be able to save the right value in the db field when the form is submitted
I am new to cakephp I found some old code and pieced together an enum select box for you enjoy
/* comments about previus answers ***
If you want to use
MySqlEnumFormHelper
instead of normal and call it by$this->Form->
instead by$this->MySqlEnumFormHelper
. You should add this line in your controller to aliasMySqlEnumFormHelper
asForm
.