Cakephp input box with enum function in MySQL
I have enum function in some of the rows and was wondering how we could fetch this in Cake to view it as select 开发者_高级运维box?
Below is the function example:
enum('Uusi hakija','Jatkohakemus','40+','60+','Työyhteisöhanke','Mieshanke','Urheiluseurahanke')
The proper "Cake" way of doing this would be to use the Array Datasource from the official datasources plugin.
You setup a model for your enum data and assign all the normal relationships. To set the data set the records property in your model like so:
public $records = array(
array('id' => '1', 'name' => 'stuff'),
array('id' => '2')
);
$enumList = enum('Your', 'stuff', 'goes', 'here');
$vars = explode('.', $enumList);
$this->Form->select('Model.field_name', $vars);
Very simple but should work. Your option
names would be 0
, 1
, 2
, etc.
Check out CakePHP's FormHelper and the select
input.
精彩评论