Can anyone tell me if there is a way to callback with the form_validation library in CodeIgniter to a utility function of a controller? I have a function called check_database that is a callback function set in form_validation's set_rules function...the problem is that it's a function in my controller which makes it visible to the router as a method.

I could navigate to index.php/controller/check_database and it will attempt to render a page rather than coming up with a 404 error. I've already tried making it a utility function by prepending an underscore to the function name, but the set_rules function doesn't seem to like callback__check_database.

Is there anyway I can specify the callback function as a utility function...or to hide a non-utility function from being visible to the router in CodeIgniter? This seems like something that should be entirely possible...or should I even be using form_validation in a Controller class?

UPDATE: Currently I have the callback set as callback__check_database and my function defined as a utility function (_check_database). This seems to work, however I can't be sure at the moment as I am briefly shown a screen that appears to have some sort of PHP error on it before it reroutes back to my login page. I'm working to find a way to capture that error now.

Did you try to write a private function instead of public like the example?
–
Maxime MorinFeb 12 '13 at 1:06

2

Odd, I've done callbacks with the underbar, and it's been fine... What exactly doesn't it like, is there an error?
–
JeemusuFeb 12 '13 at 1:07

Actually private doesn't work, I just tried it. :( The callback is being called from a library, which obviously does not have access to the private method of the controller. I also tested @Jeemusu's solution and it does work for me.
–
Maxime MorinFeb 12 '13 at 1:15

I'm not sure the value of having the function in your controller, but if it makes sense to have it there, you can modify routes.php to redirect any calls from the outside that would otherwise invoke the method. My first choice, however, would be to move it to a utilities class that both the controller and the library could load and use.
–
JerryFeb 12 '13 at 3:17