• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
put Validation Rules to the Config File

#1
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?
Q&A for Codeigniter
StartBBS--open-source, light weight forum software.
Best VPS:Digital Ocean
Reply

#2
Please update to the latest ci4 development! That will solve your problem
Need a free blog? try Mitha Blog. Here You can create a free website or build a blog with dozens of free, customizable, mobile-ready designs and themes.
Reply

#3
(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.
Q&A for Codeigniter
StartBBS--open-source, light weight forum software.
Best VPS:Digital Ocean
Reply

#4
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); 
 } 
Need a free blog? try Mitha Blog. Here You can create a free website or build a blog with dozens of free, customizable, mobile-ready designs and themes.
Reply

#5
Thanks!! ridho
Q&A for Codeigniter
StartBBS--open-source, light weight forum software.
Best VPS:Digital Ocean
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.