输入选择表单上的CakePHP标签选项无法按预期工作

时间:2011-02-09 19:43:56

标签: cakephp forms label helper

我的选择表单工作正常,但无论参数的变化或排列如何,我的标签都不会显示。

这是我的代码:

<?php echo $this->Form->input('plan_detail_id', $plans_list, array(
    'type' => 'select',
    'label' => 'Select a the Plan Detail',
    'empty' => '-- Select a the Plan Detail --'
)); ?>

正如您所看到的,我有第二个参数$plan_list,它通常是标签标签的位置。例如,我的所有其他标签都可以:

<td><?php echo $this->Form->input('age_id', array(
    'label' => 'Select an Age Range',
    'empty' => '-- Select an Age Range --'
)); ?></td>

注意:第一个例子没有第二个$argument。我做错了吗?或者这不可能或是一个错误?

1 个答案:

答案 0 :(得分:8)

The API doesn't show three parametersFormHelper::input方法;只有$fieldName$options。您可能打算使用FormHelper::select方法。

$this->Form->select('plan_detail_id', $plans_list, null, array('label' => 'Select a the Plan Detail', 'empty' => '-- Select a the Plan Detail --'));

请注意,FormHelper::select不包含换行<div>或标签。要做到这一点,你必须传递这样的东西..

echo $this->Form->input(
    'plan_detail_id',
    array(
        'options' => $plans_list,
        'type' => 'select',
        'empty' => '-- Select a the Plan Detail --',
        'label' => 'Select a the Plan Detail'
    )
);

这与您最初的尝试不同,它将$plans_list移动到设置了options参数的数组中。