I've been learning and liking the framework so far, and I was playing about with modules and themes and managed to get some working examples, but I was wondering what the best way of including custom validation rules were?
There are several ways of using custom validation rules, depending on your need.
Extending the core validation is easy, all your own rules are available immediately and everywhere, but it isn't really clean, it creates a dependency if you're not careful, and it requires a class file in the app, making it not modular at all.
- For global, app-wide rules, we use a dedicated class in app/classes
- Every module can have a class with the same name in modules/module/classes
- Every model can have model specific validation rules
And we use a method in the model to construct the validation object, which uses add_callable() to add the appropriate validation rule classes (from the list above).
You mean: if I create a Validation object in my myrules controller which is in my mymodule module?
the answer is yes, all the above options should work fine. I don't know how and where you have defined your own rules, and you try to use them, so I can't comment without more info.
I was just wondering though. Wouldn't this mean I had to define the same validation rules a few times? Say I had a rule to check for the existence of an email on both a login form and registration form if there were a login module and a registration module?