【问题标题】:cakephp : how to displays the checkbox value that has been selected in from editcakephp:如何显示已从编辑中选择的复选框值
【发布时间】:2017-07-13 04:01:13
【问题描述】:
echo $this->Form->input('product_id', array(
                                                'label'=>false,
                                                'type'=>'select',
                                                'multiple'=>'checkbox',
                                                'options'=>$product,


                                            )); 

我正在尝试从输入中添加 'checked=>true' 但失败了

这是表单编辑的截图,已经选择的数据没有被选中

【问题讨论】:

    标签: cakephp cakephp-2.0 cakephp-2.1


    【解决方案1】:

    您可以通过传递selected 值的数组来告诉CakePHP 检查了哪些复选框:-

    $selected = []; // An array of selected values
    echo $this->Form->input('product_id', array(
        'label' => false,
        'type' => 'select',
        'multiple' => 'checkbox',
        'options' => $product,
        'selected' => $selected
    ));
    

    如果您想选择所有值开始,您可以将$product 的数组键传递给selected 选项:-

    $selected = array_keys($product);
    echo $this->Form->input('product_id', array(
        'label' => false,
        'type' => 'select',
        'multiple' => 'checkbox',
        'options' => $product,
        'selected' => $selected
    ));
    

    【讨论】:

    • 如果显示的数据已经被选中或者已经保存,那怎么办?,因为已经选中了form add,那么现在问题出在form edit
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-02-08
    • 2018-03-21
    • 1970-01-01
    • 2011-03-28
    • 2019-03-17
    • 1970-01-01
    • 2017-02-07
    相关资源
    最近更新 更多