I am setting up the validation for my model using the $_properties array, based on the example here: http://docs.fuelphp.com/packages/orm/creating_models.html#/propperties
However, I have a custom validation function I'd like to use. Seeing as I'm setting up a static property, I can't include an anonymous function in the validation array. Therefore I want to use something like you'd do with an actual Validator instance: add_callable( 'myvalidationclass' ) as demonstrated here: http://docs.fuelphp.com/classes/validation/validation.html#/valid_string_rule (See the code example)
My problem is that there doesn't seem to be any way to use 'add_callable' when using the $_properties array for validation. Am I missing something or is this simply not supported?
If it is not supported, is there a way for me to get access to the validator instance associated with my Model, so I can add the rule later?
Or should I just go for a slightly hack-y way and extend Observer_Validation, run my little custom validation, then let the original before_save take over?
(On a side note, the JavaScript for the formatting buttons looks broken.)
That is the preferred way. Custom validation rules on model properties are directly tied to those properties, so the model is the obvious location for those rules.
If you have generic additional rules, creating a separate class for them and call those methods from the model validation method is a cleaner solution then extending the Validation class.
I've now hacked my way around this doing this:
Created a new class called 'Validation' in APPATH/classes/, which extends \Fuel\Core\Validation.
In APPATH/bootstrap.php, I added 'Validation' => APPPATH.'classes/validation.php', to the autoloader::add_classes array.
This simply overrides the default Validation class with the new one, and the new one contains my custom method I needed, which gets rid of my need for add_callable in the properties array.
I'm not entirely happy with this hack, so if there are any cleaner solutions, please still do let me know.