多选下拉菜单CakePHP 3选定问题

多选下拉菜单CakePHP 3选定问题,php,cakephp,Php,Cakephp,如果所选国家/地区只有一个值,则会选择该选项,但如果所选国家/地区有多个值,则不会选择任何值。如果要在$selected\u country上传递多个值,请尝试: $selected_country = array(1,3); $this->Form->input('country', [ 'options' => $source_types, 'label' => 'Country: ', 'multiple' => true,

如果所选国家/地区只有一个值,则会选择该选项,但如果所选国家/地区有多个值,则不会选择任何值。

如果要在$selected\u country上传递多个值,请尝试:

$selected_country = array(1,3);

$this->Form->input('country', [
    'options' => $source_types,
    'label' => 'Country: ',
    'multiple' => true,
    'class' => ' form-control',
    'selected' => $selected_country,
    'type' => 'select'
]);

参考:

如果要在$selected\u country上传递多个值,请尝试:

$selected_country = array(1,3);

$this->Form->input('country', [
    'options' => $source_types,
    'label' => 'Country: ',
    'multiple' => true,
    'class' => ' form-control',
    'selected' => $selected_country,
    'type' => 'select'
]);
参考资料:

适用于任何人 echo$this->Form->input'vications.\u id',['options'=>$vications',class'=>Form-control select4',label'=>false];如果您已经设置了数据库关联,并且在控制器中引用了它,就像这样

echo $this->Form->select('rooms', [
    'multiple' => true,
    // options with values 1 and 3 will be selected as default
    'default' => [1, 3]
]);
否则,在中添加“默认”=>[1,2]ID也可以,但必须先在控制器中创建,然后以列表形式馈送到视图。

对于任何这样做的人 echo$this->Form->input'vications.\u id',['options'=>$vications',class'=>Form-control select4',label'=>false];如果您已经设置了数据库关联,并且在控制器中引用了它,就像这样

echo $this->Form->select('rooms', [
    'multiple' => true,
    // options with values 1 and 3 will be selected as default
    'default' => [1, 3]
]);

否则,添加“默认值”=>[1,2]中的ID也可以工作,但必须首先在控制器中创建,然后以列表形式输入视图。

您的问题是什么?问题在国家/地区列表中不是很清楚。我们希望在国家/地区多选下拉列表中选择多个值,然后上述代码不起作用检查:@mark注释中的链接没有帮助,因为它当前不包含任何多个sAnd您的问题具体是什么?问题在国家/地区列表中不太清楚我们希望在国家/地区多选下拉列表中选择多个值,然后上述代码不起作用检查:@mark注释中的链接没有帮助,因为它当前不包含任何多个。此示例是从官方文档。此示例摘自官方文档。