![]() |
I'm converting a CI3 application to CI4 and having a little difficulty with validation.
I've been using https://codeigniter.com/user_guide/libra...ation.html and https://codeigniter.com/user_guide/insta...tions.html but my situation is still a little unclear to me. My controller has a rule and the validation check: PHP Code: $this->validator->setRule('username', 'lang:login_username', 'required|login_check'); I've created a custom validation class PHP Code: namespace app\Libraries; The problem is that formerly I had access to the request variables, because the validation function existed in the controller. I think that I need to pass Code: $this->request->getPost('password'); Code: public function login_check(string $username, string $fields, array $data, string &$error = null): bool https://codeigniter.com/user_guide/libra...aceholders seems to offer validation placeholders, so I don't know if I can use that in my custom rule and whether I can pass multiple parameters. It also doesn't give an example of the function signature for a custom rule with validation placeholders, so not real clear to me. Two bonus questions are whether or not app\Libraries\ is the best practice for where to place the custom rules classes? and the second is whether it would be best to have a separate custom validation class for each MVC triplet, or if I should have a separate custom validation rule class for each one? I lean toward having one because there is overlap, but that class might get large since I potentially have many custom validations.
As far as I'm aware you can add a new rule to the config>validation, for the POST request data I suppose you could just pass that in via a string variable which is shown in the example, but to be honest haven't tested it as such.
Practical guide to IgnitedCMS - Book coming soon, www.ignitedcms.com
|
Welcome Guest, Not a member yet? Register Sign In |