Own validation rules with CodeIgniter >4.5 |
You've modified your $rulesets array to use Traditional Rules, which the documentation say is a no-no.
"Traditional Rules exist only for backward compatibility. Do not use them in new projects. Even if you are already using them, we recommend switching to Strict Rules." Without surveying your code the difference between Strict/Traditional is that strict rules also check the type of whatever they're validating. Ozornick meant for you to look at the linked project in his signature which has a ValidationRules\ExpenseRules class which encapsulates an array of the validation rules provided by CodeIgniter. Mostly prevents code clutter in your Controllers/Models. In your case that wouldn't work because you have custom logic that is doing something outside the scope of the standard rules (which are mostly meant to validate data that is input via a form). From your class names and general logic I surmise you're attempting to determine which emails are good for a newsletter signup by eliminating those from a blacklist and making sure that a submitted email has an MX record. Your code seems fine, but I would use the validateData method rather than setRules and then run. If I were going to use run I would also do away with setRules and just created a named rule group (since you've gone through the trouble of creating a Validation class), remove the static $rules property from your Newsletter class and then execute as run($data, 'newsletter'). Read How to Save Your Rules and How to Specify Rule Group. |
Messages In This Thread |
Own validation rules with CodeIgniter >4.5 - by minsk832 - 02-05-2025, 09:08 AM
RE: Own validation rules with CodeIgniter >4.5 - by ozornick - 02-05-2025, 12:35 PM
RE: Own validation rules with CodeIgniter >4.5 - by minsk832 - 02-05-2025, 02:27 PM
RE: Own validation rules with CodeIgniter >4.5 - by grimpirate - 02-05-2025, 07:13 PM
RE: Own validation rules with CodeIgniter >4.5 - by ozornick - 02-05-2025, 10:36 PM
RE: Own validation rules with CodeIgniter >4.5 - by minsk832 - 02-07-2025, 04:49 PM
RE: Own validation rules with CodeIgniter >4.5 - by grimpirate - 02-07-2025, 06:31 PM
RE: Own validation rules with CodeIgniter >4.5 - by ozornick - 02-08-2025, 12:33 AM
RE: Own validation rules with CodeIgniter >4.5 - by grimpirate - 02-08-2025, 11:26 AM
RE: Own validation rules with CodeIgniter >4.5 - by ozornick - 02-08-2025, 01:38 PM
RE: Own validation rules with CodeIgniter >4.5 - by grimpirate - 02-08-2025, 02:28 PM
|