Log message #4125928

# At Username Text
# Mar 17th 2018, 15:15 jeremyharris hmm
# Mar 17th 2018, 15:15 jeremyharris oh I didn’t notice withCAF and caf were two different fields
# Mar 17th 2018, 15:15 kitcat711 and 'withCaf' is a boolean to inform if we nedd to take 'caf' into account
# Mar 17th 2018, 15:14 kitcat711 actually the array is 'caf' which exist anyway
# Mar 17th 2018, 15:04 adithya i don't know whats causing that
# Mar 17th 2018, 15:03 adithya @ricksaccous thank you, seems to be an issue with server the auth component works when i use bin/cake server but from my nginx setup it's not working
# Mar 17th 2018, 15:02 jeremyharris if your rule returned `true` when withCAF is false, that means no error. addNested won’t run on it because it’s not an array
# Mar 17th 2018, 15:01 kitcat711 hum, that would return an error if withCAF is false
# Mar 17th 2018, 14:59 ricksaccous @adithya all controllers extend app controller so you already added auth to all controllers
# Mar 17th 2018, 14:58 jeremyharris return true if false, false if empty array
# Mar 17th 2018, 14:58 jeremyharris then the “last” rule should be a custom rule
# Mar 17th 2018, 14:58 kitcat711 adding it in the $validator will return an error if the value is false
# Mar 17th 2018, 14:58 kitcat711 the point is: 'caf' can be false and that is not an error neither
# Mar 17th 2018, 14:56 jeremyharris you’ll have to tweak it to match your conditions, but basically if it fails that rule, it shouldn’t run anymore rules for “caf” including the nested ones
# Mar 17th 2018, 14:55 kitcat711 ok, willl try the "last rule" option
# Mar 17th 2018, 14:55 jeremyharris I added a comment for what I was thinking as the first suggestion
# Mar 17th 2018, 14:52 kitcat711 so I was trying to put the condition on the add nested
# Mar 17th 2018, 14:52 jeremyharris I think either of the options I suggested would still work. either add a “last to run” rule for the caf field itself, or re-implement the actual addNested logic
# Mar 17th 2018, 14:52 kitcat711 yes
# Mar 17th 2018, 14:52 jeremyharris kitcat711 oh I see what you’re doing now, one nested validation has the condition one does not
# Mar 17th 2018, 14:51 jeremyharris adithya: add it anywhere you want auth. usually people add it to AppController then “allow” the public pages (security “on” by default)
# Mar 17th 2018, 14:50 jeremyharris sorry I didn’t mean to imply you couldn’t reuse it, that’s exactly what addNested is great for
# Mar 17th 2018, 14:49 jeremyharris you could re-implement addNested and add your conditions. Just copy and past the ->add() logic, and put your conditions there
# Mar 17th 2018, 14:49 kitcat711 ok, so I can't reuse my paymentValidator
# Mar 17th 2018, 14:49 adithya guys, i just added the auth component in my app controller, and all my pages are from other controllers are accessible, should i add auth component to all my contrllers?
# Mar 17th 2018, 14:49 jeremyharris addNested doesn’t accept a “rule” or “on” or “message”, those are reserved for the rules in the nested validator
# Mar 17th 2018, 14:48 jeremyharris ok
# Mar 17th 2018, 14:48 jeremyharris alternatively (and maybe more clear), you can just implement the nested logic yourself, and put the conditions there.
# Mar 17th 2018, 14:47 kitcat711 https://gist.github.com/Kitcat711/441b2dd5b6b302d5db7a1f828e3ec922
# Mar 17th 2018, 14:47 kitcat711 this is what I tried
# Mar 17th 2018, 14:47 jeremyharris you might need to instruct it to be the last for that field, so the nested rules don’t run by default: https://book.cakephp.org/3.0/en/core-libraries/validation.html#marking-rules-as-the-last-to-run
# Mar 17th 2018, 14:45 jeremyharris have you tried something like `->allowEmpty('property', function ($context) { // return condition })` the add the nested below
# Mar 17th 2018, 14:44 kitcat711 if the field is true, then I must validated an array
# Mar 17th 2018, 14:43 kitcat711 property
# Mar 17th 2018, 14:43 kitcat711 condition is a field of the propert
# Mar 17th 2018, 14:41 jeremyharris or, add a rule for the actual property that has the nested array
# Mar 17th 2018, 14:41 jeremyharris what kind of condition? the nested validation rules could handle those
# Mar 17th 2018, 14:40 kitcat711 i've been trying without success
# Mar 17th 2018, 14:40 kitcat711 using cake 3.5, in $validator is it possible to ->addNested on a condition?
# Mar 17th 2018, 14:39 kitcat711 hello
# Mar 17th 2018, 14:39 bakro.istvan @dereuromark