Cakephp枚举列表,带有预先选择的下拉框

时间:2011-08-14 10:54:12

标签: php mysql cakephp

我有这个枚举选择列表预先选择了值,然后将它放入Form helper并选择如下函数:

$enumList = enum('Uusi hakija', 'Jatkohakemus', '40+', '60+','Työyhteisöhanke','Mieshanke','Urheiluseurahanke');
        $vars = explode('.', $enumList);
        echo $this->Form->select('Model.project_type', $vars);

我的问题是你如何设置它,以便用会话值定义“选定”值,如下所示?

$saved = $this->Session->read('form'); 
echo $this->Form->input('amount_accepted',array('value' => $saved['amount_accepted'] ));

1 个答案:

答案 0 :(得分:0)

在控制器中执行此操作并将其传递给视图

if (!empty($this->data)) {
 ...
} else {
 # now comes your part
 $this->data['Model']['amount_accepted'] = $this->Session->read('Model.amount_accepted');
}

PS:为什么选项如此复杂?

$this->Form->input('amount_accepted', array('options'=>array('Uusi hakija', 'Jatkohakemus', '40+', '60+','Työyhteisöhanke','Mieshanke','Urheiluseurahanke')));