修补实体时发生错误

时间:2018-08-09 10:49:07

标签: php cakephp cakephp-3.0

我正在使用cakephp 3.6&tryin'在保存之前编辑一些实体字段,所以当我使用pathchEntity编辑那些字段时:

$booking->set([
    'status'  => 1,
    'deposit' => $this->request->getData('deposit')
]);

在保存实体验证之前,我遇到了实体验证错误,因此我应该如何编辑这些字段而不会出现错误;

\src\Controller\BookingsController.php (line 253)
[
    'property_id' => [
        '_required' => 'This field is required'
    ],
    'deposit' => [
        'fileType' => 'Veuillez introduire un fichier de type: PDF, JPG.'
    ],
    'last_name' => [
        '_required' => 'This field is required'
    ],
    'first_name' => [
        '_required' => 'This field is required'
    ],
    'phone' => [
        '_required' => 'This field is required'
    ],
    'travelers_count' => [
        '_required' => 'This field is required'
    ],
    'travelers_type' => [
        '_required' => 'This field is required'
    ],
    'start' => [
        '_required' => 'This field is required'
    ],
    'end' => [
        '_required' => 'This field is required'
    ],
    'nights_count' => [
        '_required' => 'This field is required'
    ],
    'discount' => [
        '_required' => 'This field is required'
    ],
    'total' => [
        '_required' => 'This field is required'
    ],
    'total_discount' => [
        '_required' => 'This field is required'
    ]
]

1 个答案:

答案 0 :(得分:1)

您面临此错误,因为您可能已在模型中定义了以下规则。

$validator->requirePresence('user_id');

这将检查对创建和更新操作的验证。您可以如下更改

$validator->requirePresence('user_id', 'create');

这意味着验证创建操作时必须存在该字段。

https://book.cakephp.org/3.0/en/core-libraries/validation.html

希望这会有所帮助。