First, looking more deeply at the cook book on the save() command I
noticed an element for 'callbacks' which defaults to 'true' but can
also accept 'false'. So I coded up this for a save() with only the
field I wanted to update:
$this->Repairorder->save($data,
array(
'validate' => true,
'fieldList' => array(
'lof_act_60',
'lof_act_75',
'lof_act_90',
'lof'
),
'callbacks' => false
)
);
Lo and behold, none of my debug log entries fired in the beforeSave
callback method! Yeah!
So always remember that the beforeSave is useful, but can be 'hidden'
if you don't remember about it. Plus, remember you can turn off the
callback in the save() if you really want to.
I hope this helps someone else.
On Jan 22, 5:37 pm, FrederickD <manzanillo.engl...@gmail.com> wrote:
> I saw something in another post that made me stop and think. I have a
> 'beforeSave' callback in my model that sets the 'actual' dates to null
> on create or edit from a form.
>
> Of course, the 'beforeSave' was being executed before my updates. I
> commented out the 'beforeSave' just to verify. So now this code is
> working fine:
>
> $this->Repairorder->id = $data['Repairorder']['id'];
> $this->Repairorder->saveField('lof_act_60', $data['Repairorder']
> ['lof_act_60']);
> $this->Repairorder->saveField('lof_act_75', $data['Repairorder']
> ['lof_act_75']);
> $this->Repairorder->saveField('lof_act_90', $data['Repairorder']
> ['lof_act_90']);
>
> Now the question becomes, are there any ideas on how to selectively
> execute the 'beforeSave' callback in the model?
>
> Thank you for your help!
>
> On Jan 22, 5:10 pm, FrederickD <manzanillo.engl...@gmail.com> wrote:
>
> > I've been reading the manual and looking for examples, but I am still
> > having difficulty with issuing a save to update only three fields that
> > I have updated.
>
> > I have a foreach loop to read $data for records that have been
> > previously selected based on the 'scheduled' date for the reminder. I
> > am doing setup of some variables from $data values in order to send an
> > e-mail reminder for the next service interval. (Background: when a
> > repair order is created or updated, the scheduled dates for the e-mail
> > reminders are set and the 'actual' date is set to null.) After sending
> > the e-mail I want to update the 'actual' field as proof that an e-mail
> > was sent.
>
> > Here is the code I have been working with in my controller:
>
> > // Loop through eligible repair orders, send reminder, and update
> > actual date
> > foreach ( $data as $data ) {
>
> > $to = $data['Repairorder']['customer_email'];
> > $vin = $data['Repairorder']['vin'];
> > $services = $data['Repairorder']['lof'] . ' lubrication service';
> > switch($data['Repairorder']['odometer_type']) {
> > case 'Kms':
> > $interval = 5000;
> > break;
> > case 'Miles':
> > $interval = 3000;
> > break;
> > }
> > $new_odometer = $data['Repairorder']['odometer'] + $interval;
> > $odometer_type = $data['Repairorder']['odometer_type'];
>
> > // Send e-mail reminder message
> > // $id = $this->sendMail(
> > // $data['Repairorder']['id'],
> > // $to,
> > // $vin,
> > // $services,
> > // $new_odometer,
> > // $interval,
> > // $odometer_type);
>
> > // Update 'actual' date field(s)
> > if ($data['Repairorder']['lof_sch_60'] <= date('Y-m-d'))
> > $data['Repairorder']['lof_act_60'] = date('Y-m-d');
> > if ($data['Repairorder']['lof_sch_75'] <= date('Y-m-d'))
> > $data['Repairorder']['lof_act_75'] = date('Y-m-d');
> > if ($data['Repairorder']['lof_sch_90'] <= date('Y-m-d'))
> > $data['Repairorder']['lof_act_90'] = date('Y-m-d');
>
> > $this->Repairorder->id = $data['Repairorder']['id'];
> > $this->Repairorder->save($data);
> > // array('fieldlist' => array(
> > // 'lof_act_60',
> > // 'lof_act_75',
> > // 'lof_act_90'
> > // )));
>
> > /* Debug information to the error.log file in ../app/tmp/ */
> > $this->log(array(
> > 'record' => $data['Repairorder']['id'],
> > 'lof_sch_60' => $data['Repairorder']['lof_sch_60'],
> > 'lof_act_60' => $data['Repairorder']['lof_act_60'],
> > 'lof_sch_75' => $data['Repairorder']['lof_sch_75'],
> > 'lof_act_75' => $data['Repairorder']['lof_act_75'],
> > 'lof_sch_90' => $data['Repairorder']['lof_sch_90'],
> > 'lof_act_90' => $data['Repairorder']['lof_act_90']
> > ));
>
> > } // end_foreach on $data results
>
> > The log entry for each record has the correct value set for the
> > 'actual' field, but the update to the database is not occurring.
> > Ultimately I would like to provide an array with the fieldlist of the
> > three fields I want to update.
>
> > In the $data array is ['Repairorder']['id']. That should be enough to
> > access the individual record, right? I shouldn't have to set that
> > before a save, but only set it if I was doing a saveField. Is that
> > understanding correct?
>
> > Where is the error(s) in my code for the save to not work? Thank you
> > in advance for your assistance.
>
>
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 cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
No comments:
Post a Comment