Private function and Custom form validation - 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: Private function and Custom form validation (/showthread.php?tid=53030) Pages:
1
2
|
Private function and Custom form validation - El Forum - 07-08-2012 [eluser]BenAbrams[/eluser] Hi Guys I have a custom field validation rule in a config file set up, something similar to to the below: Code: array( A very simple function in my controller below just checks the input and provides a custom error message Code: public function check_terms($terms=0){ I wanted to make the function above 'private' so it couldn't be accessed by the URI but obviously this prevents the helper from accessing the function. I cant add the underscore to the function name because the callback doesn't seem to accept it. I was thinking of using the _remap function to send 'check_terms' in the uri to the 404 but this seems a little overkill. Can anyone suggest a more elegant solution? Private function and Custom form validation - El Forum - 07-08-2012 [eluser]CroNiX[/eluser] Yes, http://ellislab.com/codeigniter/user-guide/general/controllers.html#private Code: function _check_terms(){} Since callback prefixes are "callback_", and the private function is "_check_terms", it ends up being "callback__check_terms" with 2 undrescores Private function and Custom form validation - El Forum - 07-08-2012 [eluser]InsiteFX[/eluser] Ya @CroNiX, he said he tried that but then the helper will not see it. lol the old double underscore strikes again. Private function and Custom form validation - El Forum - 07-08-2012 [eluser]CroNiX[/eluser] I don't think he called the callback correctly, but he didn't post enough code to really know... Private function and Custom form validation - El Forum - 07-08-2012 [eluser]InsiteFX[/eluser] I think your right CroNiX, looks like the old double underscore problem again. Private function and Custom form validation - El Forum - 07-08-2012 [eluser]BenAbrams[/eluser] If I double underscore, instead of showing my custom message, it shows "Unable to access an error message corresponding to your field name." Private function and Custom form validation - El Forum - 07-08-2012 [eluser]CroNiX[/eluser] Did you change the name of your error message to "_check_terms" since you changed the function name? They have to be the same. Private function and Custom form validation - El Forum - 07-08-2012 [eluser]BenAbrams[/eluser] [quote author="CroNiX" date="1341766629"]Did you change name of your error message to "_check_terms" since you changed the function name? They have to be the same.[/quote] I did indeed. Private function and Custom form validation - El Forum - 07-08-2012 [eluser]CroNiX[/eluser] Strange, works just fine from here. Private function and Custom form validation - El Forum - 07-08-2012 [eluser]InsiteFX[/eluser] Code: array( Code: public function _check_terms($terms=0){ |