开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜