Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Proposal: Custom Validation Objects #912
I've packed up a solution to use custom validation rules from outside the model class namespace.
I was inspired by a discussion and code-posting I found here (http://goo.gl/8u4FN) between MarkStory and saleh.
I find this solution mandatory to CakePHP letting developers to pack validation rules into their plugins!
The validator can already use behavior functions too for validation so you can just keep all your custom functions in a behavior for easy manageability and usability. So I am not sure if the ability to use any arbitrary function for validation is really necessary.
@ADmad behaviors is meant to collect shared model logic.
I think to model logic as "what a model does with data".
Add or remove or changes validation rules applied to model's data is a model logic and should be shifted to a behavior.
Extend core validation methods adding some general pourpose validation is not responsibility of any behavior.
CakePHP core collects validation rules in a class who's not a behavior so I think my proposal is a good and correct interpretation of difference between behaviors and validation objects.
(i will fix my code to fit CakePHP standards in a few hours)