# |
Jul 27th 2021, 14:50 |
paolo.bragagni |
created myProvider.php in App/Model |
# |
Jul 27th 2021, 14:50 |
paolo.bragagni |
no bo |
# |
Jul 27th 2021, 14:48 |
paolo.bragagni |
no wait |
# |
Jul 27th 2021, 14:47 |
paolo.bragagni |
created myProvider.php in App/Model |
# |
Jul 27th 2021, 14:47 |
paolo.bragagni |
I'm not able |
# |
Jul 27th 2021, 14:34 |
admad |
4.3 will even support PHP 8.1 :) |
# |
Jul 27th 2021, 14:29 |
admad |
`void` can't be used with any other type. |
# |
Jul 27th 2021, 14:23 |
cnizzardini |
at least 4.2 should be |
# |
Jul 27th 2021, 14:23 |
cnizzardini |
it's not like cakephp 4 won't be supported for a very longtime, and its compatible with php 8 |
# |
Jul 27th 2021, 14:18 |
paolo.bragagni |
ok trying |
# |
Jul 27th 2021, 14:17 |
cnizzardini |
or the last thing in the posted snippet, which accepts a string at arg two, but the method must be static |
# |
Jul 27th 2021, 14:16 |
cnizzardini |
i'm guessing here, because i've never used them, but I imagine you could do this: `$validator->setProvider('custom', new \App\Any\Damn\Fqn\MyProvider());` |
# |
Jul 27th 2021, 14:15 |
cnizzardini |
where ever you want per the documentation |
# |
Jul 27th 2021, 14:15 |
paolo.bragagni |
where the provider logic goes? |
# |
Jul 27th 2021, 14:14 |
cnizzardini |
if you're not reusing the rule, i see no reason to create a provider and would just use a callback |
# |
Jul 27th 2021, 14:13 |
cnizzardini |
build the provider and inform Validator |
# |
Jul 27th 2021, 14:12 |
brandon |
Oof. I am only just getting around to upgrading the site 4.x. 5.x is coming this year? :cold_sweat: |
# |
Jul 27th 2021, 14:12 |
cnizzardini |
you can cargo cult something into existence |
# |
Jul 27th 2021, 14:12 |
cnizzardini |
```$validator = new Validator(); // Use an object instance. $validator->setProvider('custom', $myObject); // Use a class name. Methods must be static. $validator->setProvider('custom', 'App\Model\Validation');``` |
# |
Jul 27th 2021, 14:12 |
cnizzardini |
specifically: |
# |
Jul 27th 2021, 14:12 |
cnizzardini |
https://book.cakephp.org/4/en/core-libraries/validation.html#adding-validation-providers |
# |
Jul 27th 2021, 14:11 |
paolo.bragagni |
(if datetime I admit only date in italian, if decimal I admit only 2 decimal etc.. |
# |
Jul 27th 2021, 14:09 |
paolo.bragagni |
I'm trying to create a model.twig where I define my own default validation |
# |
Jul 27th 2021, 14:08 |
cnizzardini |
cool, i've seen lots of PR activity on it |
# |
Jul 27th 2021, 14:08 |
cnizzardini |
which i assume you might not need, especially for a one off validation, depends on what you're trying to do though... |
# |
Jul 27th 2021, 14:08 |
dereuromark |
@cnizzardini It is fair to expect somewhere this year, but usually there is no clear deadline on this. In the past it was often close to the CakeFest. |
# |
Jul 27th 2021, 14:08 |
paolo.bragagni |
probably |
# |
Jul 27th 2021, 14:07 |
cnizzardini |
i think you would need to create a custom provider? |
# |
Jul 27th 2021, 14:07 |
paolo.bragagni |
miss something? |
# |
Jul 27th 2021, 14:06 |
paolo.bragagni |
and then public function customvalidation($value,$context){ etc.. |
# |
Jul 27th 2021, 14:06 |
paolo.bragagni |
find this way (allowEmpty because otherwise the Helper shows it as required |
# |
Jul 27th 2021, 14:05 |
paolo.bragagni |
```$validator->allowEmpty('descrizione', true) ; $validator->add('descrizione',[ 'customvalidation'=>[ 'rule'=>'customvalidation', 'provider'=>'table', 'message'=>'custom message' ] ]);``` |
# |
Jul 27th 2021, 14:03 |
cnizzardini |
or this: `rule' => [$this, 'method'],` where I imagine 'methodName' must exist in your Table class |
# |
Jul 27th 2021, 14:03 |
kevin.pfeifer |
@paolo.bragagni https://book.cakephp.org/4/en/core-libraries/validation.html#using-custom-validation-rules |
# |
Jul 27th 2021, 14:02 |
cnizzardini |
```// Use a closure $extra = 'Some additional value needed inside the closure'; $validator->add('title', 'custom', [ 'rule' => function ($value, $context) use ($extra) { // Custom logic that returns true/false }, 'message' => 'The title is not valid' ]);``` |
# |
Jul 27th 2021, 14:02 |
cnizzardini |
@paolo.bragagni try using a callback |
# |
Jul 27th 2021, 14:01 |
cnizzardini |
on that note, since @dereuromark is in the room, maybe he can answer when cake 5 will be out, which will only support 8 i think? |
# |
Jul 27th 2021, 14:00 |
cnizzardini |
maybe, i haven't messed with 8 yet |
# |
Jul 27th 2021, 14:00 |
brandon |
`mixed` would likely work then, right? |
# |
Jul 27th 2021, 14:00 |
cnizzardini |
they did, `static` and `mixed` |
# |
Jul 27th 2021, 14:00 |
brandon |
I haven't been following 8 development - not sure |