What do you see in OrderModel::beforeValidate() do not prove anything
in this case. State of $this->data in OrderModel::beforeSave() have
sense. Validation and beforeValidate calls can even operate on copy of
data.

On Jun 11, 3:42 pm, Ernesto <e.fanz...@gmail.com> wrote:
> that's not correct.
>
> a pr in model::beforeValidate shows the "Code" field.
>
> the data array seems to be resetted at every behavior call
>
> On 11 Giu, 10:13, "Dr. Loboto" <drlob...@gmail.com> wrote:
>
>
>
> > I don't know why, but model data modification is possible only in
> > beforeSave method (at least in model itself) but your AutoCodeBehavior
> > try to do it in beforeValidate method.
>
> > On Jun 11, 2:38 pm, Ernesto <e.fanz...@gmail.com> wrote:
>
> > > bump!!!
>
> > > On 9 Giu, 16:20, Ernesto <e.fanz...@gmail.com> wrote:
>
> > > > here's some pr output.
>
> > > > @@@ AutoCodeBehavior @@@
>
> > > > $model->data @ AutoCode::beforeValidate (begin of function)
> > > > Note: this is the original data array returned by the view
>
> > > > Array
> > > > (
> > > >     [Order] => Array
> > > >         (
> > > >             [customer_id] => 30
> > > >             [ref] => TTTTT
> > > >         )
> > > > )
>
> > > > $model->data @ AutoCode::beforeValidate (end of function)
> > > > Note: the "Code" field is successfully added to model data array
>
> > > > Array
> > > > (
> > > >     [Order] => Array
> > > >         (
> > > >             [customer_id] => 30
> > > >             [ref] => TTTTT
> > > >             [Code] => 20090609
> > > >         )
> > > > )
>
> > > > @@@ AutoDateBehavior @@@
>
> > > > $model->data @ AutoDate::beforeSave (begin of function)
> > > > Note: the $model->data array is equal to the original one, "Code"
> > > > field is magically disappeared, maybe Cake passes the original data
> > > > array and not the modified one to every behavior?
>
> > > > Array
> > > > (
> > > >     [Order] => Array
> > > >         (
> > > >             [customer_id] => 30
> > > >             [ref] => TTTTT
> > > >         )
> > > > )
>
> > > > $model->data @ AutoDate::beforeSave (end of function)
> > > > Note: field "EstimatedDeliveryDate" is successfully added
>
> > > > Array
> > > > (
> > > >     [Order] => Array
> > > >         (
> > > >             [customer_id] => 30
> > > >             [ref] => TTTTT
> > > >             [EstimatedDeliveryDate] => 2009-06-09
> > > >         )
> > > > )
>
> > > > @@@ Model @@@
>
> > > > $this->data @ model::beforeSave
> > > > Note: there's only "EstimatedDeliveryDate" field in data array. It
> > > > seems like the first behavior didn't work at all
>
> > > > Array
> > > > (
> > > >     [Order] => Array
> > > >         (
> > > >             [customer_id] => 30
> > > >             [ref] => TTTTT
> > > >             [EstimatedDeliveryDate] => 2009-06-09
> > > >         )
> > > > )
>
> > > > On 9 Giu, 15:52, Ernesto <e.fanz...@gmail.com> wrote:
>
> > > > > here's my code.
>
> > > > > i removed all the comments.
>
> > > > > class OrderModel extends AppModel {
>
> > > > >         var $actsAs = array("AutoCode", "AutoDate");
>
> > > > >         var $validate = array(
> > > > >                 "Code" => array(
> > > > >                         "unique" => array(
> > > > >                                 "rule" => "isUnique",
> > > > >                                 "allowEmpty" => false,
> > > > >                                 "on" => "create"
> > > > >                         )
> > > > >                 ),
> > > > >         )
>
> > > > > }
>
> > > > > class AutoCodeBehavior extends ModelBehavior {
>
> > > > >         function beforeValidate (&$model) {
>
> > > > >                 $model->data[$model->alias]["Code"] = date("Ymd");
>
> > > > >                 return true;
>
> > > > >         }
>
> > > > > }
>
> > > > > class AutoDateBehavior extends ModelBehavior {
>
> > > > >         function beforeSave (&$model) {
>
> > > > >                 $model->data[$model->alias]["EstimatedDeliveryDate"] =
> > > > > date("Y-m-d");
>
> > > > >                 return true;
>
> > > > >         }
>
> > > > > }
>
> > > > > On 9 Giu, 15:04, Rob Conner <rtcon...@gmail.com> wrote:
>
> > > > > > You probably should paste code, your "in theory" based on code you
> > > > > > told us your wrote is correct. But that doesn't solve the problem. 
> > > > > > So
> > > > > > there must be some error in your code.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to