Just some thinking and a question or two, please tell me if I am
totally off base.
I would like to store multiple email addresses and phone numbers per
user. Using a serialized field might work for this. Is that a good
usage?
Next, how does one validate the data and properly save and find the
data. Here is what I am thinking (not tested).
Validate the Model using a custom validation function:
var $validate = array(
'emails' => array(
'is_email' => array(
'rule' => array('g_isEmail'),
'required' => TRUE,
'allowEmpty' => FALSE,
'message' => 'You must enter at least 1 valid email
address'
),
),
)
function g_isEmail($check){
if ( !isset($this->data['Model']['emails']) ){
return FALSE;
}
if ( is_array($this->data['Model']['emails']) ){
foreach( $this->data['Model']['emails'] as $email ){
if ( !Validate::email($email) )
return FALSE;
}
}
}elseif( !Validate::email($this->data['Model']['emails']) )
return FALSE;
}
return TRUE;
}
Then using beforeSave to serialize the field and afterFind to
unserialize the field.
Thanks,
Gary Dalton
Check out the new CakePHP Questions site http://cakeqs.org and help others with
their CakePHP related questions.
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