CodeIgniter Forums

Full Version: CI4 Validation - how use/work with calleble functions
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi everyone, I've read CI4-manual for validation library and not found example code how use/work with calleble or anonymous functions? When I use example code from CI3 - this code don't works [attachment=1491]. May be anybody know how use calleble/ anonymous functions validation in CI4-version. Sorry for my English.    

My exaple rule for email code:

PHP Code:
'email' => [

 
                   'label'  => 'Email',
 
                   'rules'  => [

 
                       'required',
 
                       'valid_email',
 
                       [
 
                           'email_exist', function( $str )
 
                           {
 
                               return $this->checkExistsUserEmail$str );
 
                           }
 
                       ]
 
                   ],
 
                   'errors' => [

 
                       'email_exist' =>'Email not found'
 
                   ]
 
               
See the news tutorial in the CodeIgniter 4 User Guide.
(04-18-2019, 04:05 AM)InsiteFX Wrote: [ -> ]See the news tutorial in the CodeIgniter 4 User Guide.


I can't find information about how to use calleble/anonymous functions in Tutorial .
Agreed - the tutorial does not appear to deal with custom validation rules Sad

Not a full example, but https://codeigniter4.github.io/CodeIgnit...stom-rules
Custom validation rules are done this way:

See https://forum.codeigniter.com/thread-72343.html
(04-18-2019, 09:37 AM)ciadmin Wrote: [ -> ]Agreed - the tutorial does not appear to deal with custom validation rules Sad

Not a full example, but https://codeigniter4.github.io/CodeIgnit...stom-rules

If I am understand right, that anonymous function was removed from validation library? And when i need to use ONE anonymous function in my rules (in my case) - i must create special custom class for that, which i registered in Config/Validation.php ? I think in this case it's not right way - create class for one rule...