![]() |
Call to undefined function validation () - 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: Call to undefined function validation () (/showthread.php?tid=79503) |
Call to undefined function validation () - lucavalentino - 06-25-2021 I am converting to codeigniter 4 In a sub view I want to show all the errors of the form. In codeigniter 3 I was using validator_errors without problems In the BaseController I loaded the Validation livery PHP Code: $this->validation = \Config\Services::validation (); In the subview it is, while the errors see exist: PHP Code: if (! empty (validation () -> listErrors ())) I get the error Code: Call to undefined function validation () RE: Call to undefined function validation () - berendbotje91 - 06-25-2021 If you want to show validation errors in a view, you need to pass validation() as a variable to the view and then call it like Code: <?= $validation->listErrors() ?> RE: Call to undefined function validation () - lucavalentino - 06-25-2021 I tried as suggested but still get the same error . In the BaseController I loaded the Validation library $validation = \Config\Services::validation (); I want to autoload the library validation RE: Call to undefined function validation () - lucavalentino - 06-25-2021 Base Controller PHP Code: <?php <?php PHP Code: namespace App\Controllers; Login view ... PHP Code: $this->include('_mesages_v', $data); _mesages_v view PHP Code: ... ERROR Undefined variable $validation RE: Call to undefined function validation () - superior - 06-25-2021 Looks like you aren't sending $validation to the view, that would explain the undefined variable message. File: _messages_v RE: Call to undefined function validation () - paulbalandan - 06-25-2021 $data['validation'] = $this-validation; view('login', $data); // view if ($validation->listErrors()) RE: Call to undefined function validation () - Gary - 06-26-2021 $this->validation and $validation likely point to different things in your case. Try using $this-> in all cases to reference the current instance of it... or using a local variable as a handle to the service that is then passed $this instance: Code: $validation = \Config\Services::validation(); Can be called in the View, if desired: echo $validation->getError('validation_test_specific_test_error'); |