Reputation: 203
how to avoid call afterSave for particular function execute in cakephp
in model i having
public function afterSave() { }
every time insert record manually using forms i need to call afterSave()...
but when i insert record using for loop. i dont want to call afterSave()....
my for loop code is
if(count($properties)>0) {
foreach($properties as $key => $value) {
$ppinsertdata = array(
'id' => '',
'property_id' => $value,
'plan_id' => ConstPropertyPlan::Free,
'is_expired' => 0,
'expiry_date' => date('Y-m-d', strtotime("+$duration days",time()))
);
$this->PropertyPlan->save($ppinsertdata);
$pplastinsertid = $this->PropertyPlan->getLastInsertID();
$updateproperty['id'] = $key;
$updateproperty['property_plan_id'] = $pplastinsertid;
$updateproperty['plan_id'] = ConstPropertyPlan::Free;
$this->Property->save($updateproperty);
}
}
i got error this line $this->PropertyPlan->save($ppinsertdata);
how to avoid to call afterSave() in this scenario
Pls help me to solve this solution....
Upvotes: 0
Views: 2521
Reputation: 31749
Try this -
$this->PropertyPlan->save($ppinsertdata, array('callbacks' => false)); //for disabling all callbacks
Read This -
callbacks Set to false to disable callbacks. Using ‘before’ or ‘after’ will enable only those callbacks
save() - cakephp
Upvotes: 2