How do I put form callbacks in a helper file? |
[eluser]Ninjabear[/eluser]
Hi. I've been copying my callbacks from controller - controller every time I use them. This means duplicating code which I don't like. I tried to put them all in a helper which I called callback_helper.php. I've used helpers before so I know how to make them work but for some reason the form_validation class is not seeing them. Also the callbacks are working when they are in the controller just in case you were wondering. Code: $autoload['helper'] = array('url','form','content','callback'); I'm thinking this could be a load-order thing. Are helpers loaded before controllers? Maybe I shouldn't use a helper but some kind of class? BTW: I searched google / CI forum but I couldn't find anything useful on this subject. My helper in case you need it: Code: <?php
[eluser]Matalina[/eluser]
I don't know if there is another way, but I create a library validation method per usual. And then for each call back in the controller, load the helper and call the helper I need inside of the controller.
[eluser]Ninjabear[/eluser]
[quote author="Matalina" date="1331129025"]I don't know if there is another way, but I create a library validation method per usual. And then for each call back in the controller, load the helper and call the helper I need inside of the controller. [/quote] Sounds interesting but I don't know what you mean by library validation methods. I found an article here: http://www.scottnelle.com/41/extending-c...n-library/ Are you talking about extending the CI validation class or some other thing?
[eluser]Matalina[/eluser]
No. You said you wanted to but your callback functions in a library. In your library you would have your validation call back login. In your controller you would load said library and call the call back function.
[eluser]CroNiX[/eluser]
Why don't you just extend CI's validation library with your own rules? /application/libraries/MY_Form_validation.php Code: class MY_Form_validation extends CI_Form_validation { Now when setting your rules, you just use the rule name "as is" like the native rules instead of "callback_rule_name". Code: $this->form_validation->set_rules('field', 'Field', 'required|Valid_Date_Format'); |
Welcome Guest, Not a member yet? Register Sign In |