Friday, August 24, 2012

Re: Previous Value beforeSave

Don't use read(). From the API:

"Returns a list of fields from the database, and sets the current model data (Model::$data) with the record found."

Not what you want!

Does the model declare a ModifiedValues member variable? If not, this will silently fail because the assigned value will not carry over to other methods.

On Fri, Aug 24, 2012 at 11:03 AM, thecosinus <fabien.gaubert@gmail.com> wrote:
> I would like to get the value that was in database before a save in order to
> send an email saying that the content toto has chnaged to tata.
>
> How could I get the previous value. I ve tried with beforeSave but it doesnt
> work
>
> function beforeSave($options){
>
>             $value  = $this->read();
>             $this->ModifiedValues = $value['Boite'];
>            
>             return true;
>
>         }
>
>
>          function afterSave($created){
>
>             $addValues = $this->read();
>             if ( $created ) {
>                 $mailOptions['subject']        = __('MailObjectAjoutBoite');
>                 $mailOptions['templateView']   = 'ajout_feminin';
>                 $mailOptions['templateLayout'] =
> 'avec_signature_fournitures';
>
>                 $mailOptions['viewVars'] = array(
>                                         'value' => 'boîte',
>                                         'name'  =>
> $addValues['Boite']['name'],
>                                         'id'    => $addValues['Boite']['id']
>                                     );
>             } else {
>                 $mailOptions['subject']        =
> __('MailObjectModificationBoite');
>                 $mailOptions['templateView']   = 'modification_feminin';
>                 $mailOptions['templateLayout'] =
> 'avec_signature_fournitures';
>
>                 $mailOptions['viewVars'] = array(
>                                         'value'  => 'boîte',
>                                         'name'   =>
> $addValues['Boite']['name'],
>                                         'id'     =>
> $addValues['Boite']['id'],
>                                         'before' =>
> $this->ModifiedValues['name']
>                                     );
>             }
>
>            
>
>             $this->mail_send($mailOptions);
>         }
>
>
> Thanks
>
> --
> 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+unsubscribe@googlegroups.com.
> Visit this group at http://groups.google.com/group/cake-php?hl=en-US.
>  
>  

--
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+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.
 
 

No comments: