cakephp: Validation rule can not be added without a name
This is a (multiple allowed):
-
bug
-
enhancement
-
feature-discussion (RFC)
-
CakePHP Version: 4.0.0
What you did
this doesn’t work:
public function validationDefault(Validator $validator): Validator
{
return $validator
->add('date_field', [
['rule' => 'date', 'provider' => 'custom'],
])
}
this works:
public function validationDefault(Validator $validator): Validator
{
return $validator
->add('date_field', [
'validationRuleName' => ['rule' => 'date', 'provider' => 'custom'],
])
}
What happened
Argument 1 passed to Cake\Validation\ValidationSet::add() must be of the type string, int given, called in vendor/cakephp/cakephp/src/Validation/Validator.php on line 475
What you expected to happen
Validation rule added successfully without having to add a name
Possible solution
revert add-method in ValidationSet class
from
public function add(string $name, $rule)
back to
public function add($name, $rule)
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 16 (16 by maintainers)
A PR now open , follow discussion there thanks
This would be my idea: https://github.com/cakephp/cakephp/pull/14041