I created a new way of creating validation rules for models, which I
think is kind of slick, but I don't really think the way I have it
working is very "cake-like" and I need some advice on how best it
should be implemented.

Right now in a model I am doing the following to add my RuleBuilder

<?php
require_once('validation/RuleBuilder.php');

class Company extends AppModel{
...
var $validate = array()
...
function beforeValidate()
        {
                $field_name = new ValidationField('name');
                $field_name->addRule(new AlphaNumSpaceRule(true, false));

                $field_contactName = new ValidationField('contact_name');
                $field_contactName->addRule(new AlphaNumSpaceRule(true, false));

                $field_phoneNumber = new ValidationField('contact_number');
                $field_phoneNumber->addRule(new PhoneNumberRule());

                $this->validate = array_merge($field_name-
>getFieldAsArray(),
                                                                          
$field_contactName->getFieldAsArray(),
                                                                          
$field_phoneNumber->getFieldAsArray());
}

What the code is doing is really just building the validates array by
using the builder design pattern. The good part is that adding
validation rules to your model is easy, it is simple to add multiple
validation rules to a field, and any custom validation rules (i.e. the
AlphaNumSpaceRule) you create are shared among all of the models.

My question is, should I be using a behavior, or is it ok, from a cake
perspective, to just go with my current implementation?

BTW, I think I can use $array1 += $array2 etc... instead of
array_merge which should help performance but I have not tried it yet.

Thanks in advance!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to