Call to undefined function validation () |
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 ()
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() ?>
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
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
Looks like you aren't sending $validation to the view, that would explain the undefined variable message.
File: _messages_v
$data['validation'] = $this-validation;
view('login', $data); // view if ($validation->listErrors())
$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'); |
Welcome Guest, Not a member yet? Register Sign In |