CodeIgniter Forums
CI4 Validation - how use/work with calleble functions - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forum-30.html)
+--- Thread: CI4 Validation - how use/work with calleble functions (/thread-73377.html)



CI4 Validation - how use/work with calleble functions - Avega Soft - 04-17-2019

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'
 
                   ]
 
               



RE: CI4 Validation - how use/work with calleble functions - InsiteFX - 04-18-2019

See the news tutorial in the CodeIgniter 4 User Guide.


RE: CI4 Validation - how use/work with calleble functions - Avega Soft - 04-18-2019

(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 .


RE: CI4 Validation - how use/work with calleble functions - ciadmin - 04-18-2019

Agreed - the tutorial does not appear to deal with custom validation rules Sad

Not a full example, but https://codeigniter4.github.io/CodeIgniter4/libraries/validation.html#creating-custom-rules


RE: CI4 Validation - how use/work with calleble functions - donpwinston - 04-18-2019

Custom validation rules are done this way:

See https://forum.codeigniter.com/thread-72343.html


RE: CI4 Validation - how use/work with calleble functions - Avega Soft - 04-19-2019

(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/CodeIgniter4/libraries/validation.html#creating-custom-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...