CodeIgniter Forums
put Validation Rules to the Config File - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=31)
+--- Thread: put Validation Rules to the Config File (/showthread.php?tid=66604)



put Validation Rules to the Config File - startbbs - 11-10-2016

IN CI4,
I put the Validation Rules to the Config File(Validation)
Code:
    // Rules
    public $signup = [
       'username'     => 'required',
       'password'     => 'required',
       'pass_confirm' => 'required|matches[password]',
       'email'        => 'required|valid_email'
   ];

here I test it in Controller:



PHP Code:
            $validation  \Config\Services::validation();
            
$data=array(
                
'email'=>'',
                
'username'=>'',
            );
            
$validation->run($data$signup);
            
$errors $validation->getErrors();
            
print_r($errors); 
I got the ErrorException #1

Method CodeIgniter\HTTP\Header::__toString() must not throw an exception, caught ErrorException: Array to string conversion


 what went wrong?


RE: put Validation Rules to the Config File - ridho - 11-13-2016

Please update to the latest ci4 development! That will solve your problem


RE: put Validation Rules to the Config File - startbbs - 11-14-2016

(11-13-2016, 10:00 PM)ridho Wrote: Please update to the latest ci4 development! That will solve your problem


same errors as before after updated.


RE: put Validation Rules to the Config File - ridho - 11-14-2016

It's working with my following controller code:

PHP Code:
public function index()
 {
 
           $validation  \Config\Services::validation();
 
           $data=array(
 
               'email'=>'',
 
               'username'=>'',
 
           );
 
           $validation->run($data'signup');
 
           $errors $validation->getErrors();
 
           print_r($errors); 
 } 



RE: put Validation Rules to the Config File - startbbs - 11-14-2016

Thanks!! ridho