为什么我的自定义验证方法返回数组格式的错误消息
Why is my custom validation method returning an error message in array format
这是我的自定义验证方法:
$validator
->notEmpty('postcode', 'Postcode should not be empty')
->add('postcode', [
'postcode_valid'=> [
'provider' => 'table',
'rule' => 'validatePostcode',
'message' => 'Bitte geben Sie eine gültige Postleitzahl ein',
]
]);
如果在邮政编码字段中输入了一些无效数据,table 的 errors()
方法将 return 一个像这样的数组:
Array
(
[address] => Array
(
[postcode] => Array
(
[postcode_valid] => Bitte geben Sie eine gültige Postleitzahl ein
)
)
)
为什么多了一个数组?所有其他验证错误消息都只是字符串。我可以将我的自定义验证方法更改为仅 return 一个字符串吗?
验证错误不是由主模型造成的,而是由关联模型造成的,因此还有一个以模型名称作为键的包装数组。
(在我的示例中,它是一个注册表单。主模型是 user
,表单的某些字段属于关联模型 address
。其中一个字段造成了验证错误) .
这是我的自定义验证方法:
$validator
->notEmpty('postcode', 'Postcode should not be empty')
->add('postcode', [
'postcode_valid'=> [
'provider' => 'table',
'rule' => 'validatePostcode',
'message' => 'Bitte geben Sie eine gültige Postleitzahl ein',
]
]);
如果在邮政编码字段中输入了一些无效数据,table 的 errors()
方法将 return 一个像这样的数组:
Array
(
[address] => Array
(
[postcode] => Array
(
[postcode_valid] => Bitte geben Sie eine gültige Postleitzahl ein
)
)
)
为什么多了一个数组?所有其他验证错误消息都只是字符串。我可以将我的自定义验证方法更改为仅 return 一个字符串吗?
验证错误不是由主模型造成的,而是由关联模型造成的,因此还有一个以模型名称作为键的包装数组。
(在我的示例中,它是一个注册表单。主模型是 user
,表单的某些字段属于关联模型 address
。其中一个字段造成了验证错误) .