![]() |
Controller's variable $validator: wrong Validation class? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: Controller's variable $validator: wrong Validation class? (/showthread.php?tid=74591) |
Controller's variable $validator: wrong Validation class? - Ekley - 10-12-2019 Hello ![]() I searched for a similar topic but I didn't find any... so I hope it won't be redundant. I have an "issue" (or, at least, a comprehension issue) with the initialization of the variable $validator in the CodeIgniter\Controller class. Let me explain: - I extended the CodeIgniter\Validation\Validation class with additional methods: PHP Code: <?php namespace App\Libraries; - I rewrote the validation() method in the Config\Services class to instanciate my custom class (as explained in the user guide): PHP Code: public static function validation(\Config\Validation $config = null, bool $getShared = true) - in my custom controller, I use the method validate() from the class CodeIgniter\Controller. For information, this method initializes the variable $validator: PHP Code: protected function validate($rules, array $messages = []): bool What I expect: the variable $validator is an instance of my custom Validation class. What I get: the variable is an instance of CodeIgniter\Config\Services class. Knowing the philosophy of the framework and the extensibility it provides, it seems to be bug. If not, could it be clearly stated when CodeIgniter\Config\Services is preferred to App\Config\Services, please? At least to know when we can rely on our custom extensions of CI. If it is done on purpose, obviously, I'll rewrite the validate method in my custom Controller. Regards and thank you! |