Welcome Guest, Not a member yet? Register   Sign In
Confusion over adding validation RuleSet classes
#1

(This post was last modified: 06-01-2023, 09:34 AM by twistedpixel. Edit Reason: Formatting )

Trying to get to grips with CI4 and I'm struggling to get my custom validation RuleSet class to load.

I've read the documentation here which describes that you first add the class `app/Config/Validation.php` under the `$ruleSets` array (which I've done as `CustomRules::class`).

I then create my class `CustomRules` in a file called `CustomRules.php` inside app/Libraries (I tried also in app/Controllers but it made no difference).

At the top of `app/Config/Validation.php` I've also added `use App\Libraries\CustomRules;`

But I get the error: 'Class "App\Libraries\CustomRules" not found' referencing SYSTEMPATH/Validation/Validation.php at line 596 which is where each set of rules is loaded (`$this->ruleSetInstances[] = new $file();`)

Am I missing something here? Is there somewhere else I need to reference this file?

My CustomRules class is extremely simple and exactly as is described in the documentation:
Code:
<?php

class CustomRules {

    public function valid_enzymes($value, ?string &$error = null): bool {
        
    }

}
Reply
#2

you're missing a namespace declaration.
Reply
#3

It seems you need to learn PHP's namespaces.
See https://www.w3schools.com/php/php_namespaces.asp
Reply
#4

Yep, that's what it was. My knowledge on namespacing is not great. Definitely time to get to grips with it.

Thanks.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB