Welcome Guest, Not a member yet? Register   Sign In
Calling setRules multiple times possible?
#1

(This post was last modified: 09-06-2022, 05:30 AM by groovebird.)

Hi,

i want to add an array of additional validation rules to en existing array of rules.

$validation->setRules($firstArrayWithRules);
$validation->setRules($secondArraywithRules);

If i call this in the controller only the second array with rules will be executed and the first rules are ignored.

Is there something like addRules, where i can add additional rules to the rules set by setRules method?
Reply
Reply
#3

(09-06-2022, 06:15 AM)superior Wrote: Like this?
https://www.php.net/manual/en/function.array-merge.php

Yes, i did it this way but thougt there was an codeigniter native functionality for the validation rules. With a helper function in my controller i collect all rules and pass it to the setRules method. I think if i call the setRules method twice, the first rules are overwritten and set new by the second call
Reply
#4

So why don't you build the array first before sending this to the setRules() method?
Reply
#5

Logically, the "setX" action should overwrite the previous value. To add to lists it is possible to have "addX"
So create an array before validation
P.S. Not really an answer, but a hint
Reply




Theme © iAndrew 2016 - Forum software by © MyBB