【问题标题】:CakePHP label option on input select form not working as expected输入选择表单上的 CakePHP 标签选项未按预期工作
【发布时间】:2011-06-24 09:28:40
【问题描述】:

我的选择表单运行良好,但无论参数的变化或排列如何,我的标签都不会显示。

这是我的代码:

<?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 像第一个示例一样。我做错了什么吗?或者这是不可能的还是一个错误?

【问题讨论】:

    标签: cakephp forms label helper


    【解决方案1】:

    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 不包含包装 &lt;div&gt; 或标签。为此,您必须传递类似这样的内容..

    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 参数集的数组中。

    【讨论】:

    • 之前试过了,还是不行,而且预先输入的选择项也不显示:(
    • 你的意思是没有代码可以显示吗?定义“不起作用”
    • 预定义的第一个选择框消失(从“空”开始),选择框上方再次没有显示标签。但是在我的代码中,标签确实显示在查看源代码中???只是不会显示在实际的 UI 上??
    • 我修正了答案。我忘记在查询中包含$selected 参数。
    • 这是我的下一个想法。谢谢。像魅力一样工作:)
    猜你喜欢
    • 2016-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-05
    • 1970-01-01
    • 2021-12-28
    • 1970-01-01
    相关资源
    最近更新 更多