CakePHP 1.3 FormHelper输入“已选择”不起作用

时间:2012-02-27 18:40:34

标签: php html cakephp

首先,$ questions数组:

    Array
    (
        [2] => How much do you like cheese?
        [3] => How much do you like cake?
        [6] => Is this question successfully added?
    )

以下是我在输入中尝试使用它的方法:

   <td>
       <?php echo $this->Form->input('question', array(
             'options' => $questions,
             'selected' => $questions[6], 
             'name' => 'data[ResponseActions]['.$responseAction['responses_actions']['id'].'][question_id]')); 
       ?>
   </td>

但是,无论何时呈现页面,默认情况下始终选择元素2。有谁知道我为什么会遇到这个问题?

2 个答案:

答案 0 :(得分:2)

selected选项需要密钥,而不是值。

'selected' => 6 

答案 1 :(得分:1)

试试这个

Array
    (
        '2' => 'How much do you like cheese?'
        '3' => 'How much do you like cake?'
        '6' => 'Is this question successfully added?'
    )

<?php echo $this->Form->input('question', array(
             'options' => $questions,
             'selected' => '6', 
             'name' => 'data[ResponseActions]['.$responseAction['responses_actions']['id'].'][question_id]')); 
       ?>