Welcome Guest, Not a member yet? Register   Sign In
Custom validation callback technique
#1

[eluser]CodeOfficer[/eluser]
This is a question regarding CI's custom validation callback technique. As far as I can tell, validation callback methods need to be in the controller class ... which is bad in my case, as multiple controllers might deal with this sort of validation potentially.

Another way I can think to get this stuff out of my controller is to extend the validation class and put them in my custom version ... yet even that doesn't seem an attractive idea at the moment. Are there other popular methods for handling this?###
#2

[eluser]deviant[/eluser]
Well, CI tries to use a PHP function if all else fails. I'm not sure if it would work but you could put the callback function in (for example) a plugin, which you load when you need it. Since it would just be a normal PHP function I assume the validation class should pick up on it.
#3

[eluser]Michael Wales[/eluser]
I'm not sure if that would work... the callback function is a method of that particular class - whereas helpers/plugins are simply functions, that are just there.

There is a 3rd party Validation that allows you to setup Validator files - which are kind of like models, but for validation only. This would give you the seperation and re-usability you are looking for.
#4

[eluser]BravoAlpha[/eluser]
[quote author="deviant" date="1188481492"]I'm not sure if it would work but you could put the callback function in (for example) a plugin, which you load when you need it.[/quote]
I just tried this and it didn't work.
#5

[eluser]CodeOfficer[/eluser]
[quote author="walesmd" date="1188516650"]There is a 3rd party Validation that allows you to setup Validator files - which are kind of like models, but for validation only. This would give you the seperation and re-usability you are looking for.[/quote]

Where would I find this specific library, in the wiki?
#6

[eluser]Michael Wales[/eluser]
Look around in the Ignited Code forum - I believe it was there. If I come across I'll post a link.
#7

[eluser]CodeOfficer[/eluser]
still looking, thanks!
#8

[eluser]Michael Wales[/eluser]
Validation Class Extension
#9

[eluser]CodeOfficer[/eluser]
Awesome thanks Mike Smile appreciated. I'll check it out
#10

[eluser]deviant[/eluser]
[quote author="BravoAlpha" date="1188524493"][quote author="deviant" date="1188481492"]I'm not sure if it would work but you could put the callback function in (for example) a plugin, which you load when you need it.[/quote]
I just tried this and it didn't work.[/quote]

Well I just tried this and it did work. Don't prefix the function name with callback_ in the validation rules and it does exactly what its supposed to.




Theme © iAndrew 2016 - Forum software by © MyBB