Welcome Guest, Not a member yet? Register   Sign In
Own validation rules with CodeIgniter >4.5
#6

(This post was last modified: 02-07-2025, 04:49 PM by minsk832.)

Thank you very much for your feedback. To be honest, I'm still a bit in the fog, although I have looked at the code and the documentation again.

Quote:You've modified your $rulesets array to use Traditional Rules, which the documentation say is a no-no.

My $ruleSets array:

PHP Code:
    public array $ruleSets = [
        Rules::class,
        \App\Validation\NewsletterRules::class,
        FormatRules::class,
        FileRules::class,
        CreditCardRules::class,
    ]; 

But the documentary says:
https://codeigniter.com/user_guide/libra...rict-rules

Quote:Since v4.3.0, Strict Rules are used by default for better security.

And you can also see above:

PHP Code:
use CodeIgniter\Validation\StrictRules\CreditCardRules;
use 
CodeIgniter\Validation\StrictRules\FileRules;
use 
CodeIgniter\Validation\StrictRules\FormatRules;
use 
CodeIgniter\Validation\StrictRules\Rules

Maybe I haven't really understood what $ruleSets is used for in the system. My understanding was: If I don't register the class there, the system can't do anything with rules like hasValidMxRecord.

In the example code, however, I don't see it registered in $ruleSets and it's called

PHP Code:
if ($this->validateData($inputExpenseRules::create()) === false) {
 
    return redirect()->back()->withInput()->with('validation'$this->validator->getErrors());


instead of

PHP Code:
$validation service('validation');
$validation->setRules(NewsletterRules::$rules);
if (!
$validation->run($insertData)) {
    return $this->response->setJSON([
 
        'status' => 'error',
 
        'code' => 'validation_failed',
 
        'message' => implode(', '$validation->getErrors()),
 
    ]);


But from the documentation I primarily see the path via $validation->setRules().

Where am I missing the connection or understanding? What exactly in my code is causing me to not follow the strict recommendation in the documentation?
Reply


Messages In This Thread
RE: Own validation rules with CodeIgniter >4.5 - by minsk832 - 02-07-2025, 04:49 PM



Theme © iAndrew 2016 - Forum software by © MyBB