On Wed, Apr 28, 2010 at 3:15 AM, Jonas <[email protected]> wrote:
> Hello,
>
> Can I validate an array that looks like this somehow with the standard
> validation rules?
>
> [Trip]
> [Passengers]
> [1] => Array
> (
> [passenger_firstname] =>
> [passenger_lastname] =>
> [passenger_date_of_birth] => 1970-01-01
> [passenger_gender] =>
> [passenger_nationality] => GB
> )
> [2] => Array
> (
> [passenger_firstname] =>
> [passenger_lastname] =>
> [passenger_date_of_birth] => 1970-01-01
> [passenger_gender] =>
> [passenger_nationality] => GB
> )
>
> I need to write a rule to ensure that firstname & lastname isn't
> empty, date of birth is within certain ages etc.
>
> My current rule looks like this:
>
> var $validatePassenger = array(
> 'passenger_firstname' => array(
> array('rule' => array('validateArrayBetween',
> 1, 30)),
> ),
> 'passenger_lastname' => array(
> array('rule' => array('validateArrayBetween',
> 1, 30)),
> ),
> );
>
>
> but it doesn't work since it requires passenger_firstname to be
> directly under [Trip] (or so I think?)
>
> Can someone help me out here...?
You should put Passenger's validation on Passenger's Model. It seems
you have Trip hasMany Passenger association.
If you're saving from trip's controller then you could something like:
$this->Trip->saveAll($this->data, array('validate' => 'first'));
--
regards,
gedex
blog: http://gedex.web.id
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