I found my problem... I changed the way I assigned the local $data to the model's $data: // in my model Old: $this->data = $data; New: $this->set($data);
And now it works great! Thanks a lot Cake for an excellent framework! S On Mar 12, 11:26 am, starkey <[email protected]> wrote: > I forgot to mention that I also tried other validation rule formats, > e.g. 'rule' => array('date','mdy'), without any luck. The > Validation::date method gets passed an array when calling validateData > from my model while Model::save() sends it a string. > > Thanks again! > > On Mar 12, 11:16 am, starkey <[email protected]> wrote: > > > Hello all! > > > I'm using 1.2.1 > > > I used to just have Cake validate my data in the save() method. Now I > > need to validate the data before the save, so I call $this->validateData() > > inside my model before the save(). My dates used to > > > validate fine when calling save(), now they all fail when I call > > validateData. It seems that save() changed the date array into a > > string before passing it to the date validation function. It seems > > I'll have to change the date array into a string before calling > > validateData then change it back to an array for save. I figure I'm > > missing something b/c Cake is usually much more programmer friendly! > > > I have a date field that is created like this in my view: > > echo $form->input('Punch.workdate', > > array('maxYear'=>$yr, > > 'minYear'=>--$yr, > > 'div'=>false, > > 'label'=>false, > > 'dateFormat'=>'mDY')); > > > In my model I have this validation: > > 'workdate' => array( > > 'rule' => array('date','ymd'), > > 'message' => 'Date is not valid.', > > 'allowEmpty' => false > > ), > > > Then in my model I've customized the save() method: > > function save($data) > > { > > $bRet = false; > > // some logic against $data > > $this->data = $data; > > if ($this->invalidFields()) { > > return parent::save(); > > } > > return false; > > } > > > Unfortunately, the data is never saved because the date fails (even > > though it is valid). The date array will look like this: > > data[Punch][workdate][month] = '03' > > data[Punch][workdate][day] = '12' > > data[Punch][workdate][year] = '2009' > > > Any help would be greatly appreciated! > > S --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
