在CakePHP v3.4.14中使用FormHelper :: file时,SecurityComponent上的CSRF错误
POST数据中的意外字段'settings.server.bookings_email_image', 缺少字段'settings.server.bookings_email_image.name, settings.server.bookings_email_image.type, settings.server.bookings_email_image.tmp_name, settings.server.bookings_email_image.error, POST数据中的settings.server.bookings_email_image.size'
代码:
<?php echo $this->Form->create(null,['id'=>'publisher-form']) ?>
echo $this->Form->file("settings.$domain.$id", [
'label' => $setting->label . ($setting->required === true ? ' (Required)' : '' ),
]);
<?php echo $this->Form->end(); ?>
解决方法:
$this->Form->unlockField("settings.$domain.$id");
$this->Form->unlockField("settings.$domain.$id.name");
$this->Form->unlockField("settings.$domain.$id.type");
$this->Form->unlockField("settings.$domain.$id.tmp_name");
$this->Form->unlockField("settings.$domain.$id.error");
$this->Form->unlockField("settings.$domain.$id.size");
我必须解锁这个领域似乎很愚蠢。在处理文件时,您需要做些什么特别的事情吗?