How to use validation check with validation geterrors? |
I'm using Codeingiter 4 with php 8.
I'm trying to validate values before they are set in an entity. Then I call the validation getErrors function to pass them to the view. The problem is that service('validation')->getErrors() prints "The field check is mandatory." My field is called Number not check. The function is check. Is this a bug, if this isn't a bug how can I group all my errors together or do I use the check function? Also an unrelated question what does the return $this; do in a set function of entity. I saw this in the documentation. I do something like this: PHP Code: <?php PHP Code: <?php If you see other problems please tell me. I'm not good at this.
Hi!
return $this is for method chaining as far as i know. I'm not sure about this line: PHP Code: if(service('validation')->check($pass, $this->validationRules['Number'] )){ I would try PHP Code: if(service('validation')->check($pass, 'Number' )){
Entity is not for validation.
Entity to represent a record from a database. For validation, you can use a model or a service or a controller. (12-20-2021, 01:40 PM)Kabouter Wrote: The problem is that service('validation')->getErrors() prints "The field check is mandatory." My field is called Number not check. The function is check. Is this a bug, if this isn't a bug how can I group all my errors together or do I use the check function? It is not a bug. It seems it is by design. It seems `check()` does not care about the error message. check() is to validate only one value one time. It resets the all data and validates the value. You can't use check() for your use case. If you want to validate and want to get correct error messaages, use `run()` instead. But your use case validates only one value., so run() is also not good for it...
The entity is not intended for validation.
Representational object for a database record. waffle game
It would seem that the function 'check()' does not care about the error message.
|
Welcome Guest, Not a member yet? Register Sign In |