2009-09-07 55 views
0

我正在爲我的應用程序使用jQuery和CakePHP。

在我的應用程序中,我已經保存在數據庫中的數據,例如,如果字段類型列是文本,然後我使用$ form-> input()在我的代碼中生成一個文本框;

如果它是一個下拉框,我使用它生成:

echo $form->input($r['Attribute']['label'], 
    array('id'=>$r['Attribute']['id'],'name'=>$r['Attribute']['label'], 
     'options' => array(1,2,3,4,5))); 

現在我有型「單選按鈕」的領域。我正在嘗試在CakePHP中創建單選框。 是否有可能......如果是這樣的話?

回答

4

使用FormHelper::input(),您可以通過設置選項type指定所需的字段類型:不同於直接調用FormHelper::radio()

echo $form->input($r['Attribute']['label'], array(
    'type' => 'radio', 
    'id' => $r['Attribute']['id'], 
    'name' => $r['Attribute']['label'], 
    'options' => array(1, 2, 3, 4, 5), 
)); 

,輸入的標籤和驗證錯誤會被渲染。

+0

而一個回合布爾收音機嗎?輸入數據庫值是布爾類型,但蛋糕(或PDO)顯示'f'和't'?我無法得到te布爾值來設置正確的無線電選項(在edit.cpt上)。 – 2013-11-22 12:38:02

1

例如:

$options=array('M'=>'Male','F'=>'Female'); 
$attributes=array('legend'=>false); 
echo $this->Form->radio('gender',$options,$attributes); 

嘗試用你的屬性

+0

和布爾無線電?輸入數據庫值是布爾類型,但蛋糕(或PDO)顯示'f'和't'?我無法得到te布爾值來設置正確的無線電選項(在edit.cpt上)。 – 2013-11-22 12:38:16

0
echo $form->input($r['Attribute']['label'], 
    array('id'=>$r['Attribute']['id'],'name'=>$r['Attribute']['label'], 
     'type'=>'radio', 
     'options' => array(1=>'male',2=>'female',3=>'Others') 
    ));