In the docs, it says a null
key-presence is counted as valid. Is there a way to check for null
values ? Maybe something like notNullValue
option in the validator ?
Key presence is checked by using array_key_exists() so that null values will count as present. You can set the mode using the second parameter:
Problem example :
// in src/Modal/Table/xx.php
$validator
->nonNegativeInteger('working_status')
->requirePresence('working_status', true )
->notBlank('working_status')
->notEmptyString('working_status');
After creating an entity (newEntity), there are errors reported by the entity. Once I set the field to null
, the error disappears even though notEmptyString
is in the validator.
// To simplify stuff. A simple array
// Error will be reported by entity ([hasErrors] => true)
$newEntity = $this->Users->newEntity([
'working_status' => null
]);
// No error will be reported by entity after setting it to null ([hasErrors] => false)
$newEntity->working_status = null;