![]() |
Can not Define Callback function in Codeigniter - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Can not Define Callback function in Codeigniter (/showthread.php?tid=59318) |
Can not Define Callback function in Codeigniter - El Forum - 09-20-2013 [eluser]Unknown[/eluser] Hi, i am using CI 2.1.4 I want use callback in my model, this is code My callback function Code: public function check_state_license_number($license_number){ my config Code: $conf = array( I am sure set validate rules before call run_validation, but it can't validate. Is CI allow define callback in Model ? Can not Define Callback function in Codeigniter - El Forum - 09-20-2013 [eluser]noideawhattotypehere[/eluser] Create file in application/libraries called MY_Form_validation.php paste this Code: <?php Can not Define Callback function in Codeigniter - El Forum - 09-20-2013 [eluser]CroNiX[/eluser] Callback functions can only be defined in the controller where they are used in the form validation. You can extend the Form_validation library with your own custom rules and then those could be used anywhere. You also need to define the error message for that rule or nothing will be displayed and the user won't know what field didn't pass validation. /application/libraries/MY_Form_validation.php Code: class MY_Form_validation extends CI_Form_validation Now this is no longer a "callback", but a regular rule. So when setting the validation rules just leave off "callback_", like: Code: 'rules' =>'required|check_state_license_number' Can not Define Callback function in Codeigniter - El Forum - 06-26-2014 [eluser]Unknown[/eluser] Worked fine.. tnx |