如何避免在cakephp中执行特定函数执行后调用afterSave
在模特i中
public function afterSave(){ }
每次使用表格手动插入记录我需要调用afterSave()...
但是当我使用for循环插入记录时。我不想打电话给AfterSave()....
我的for循环代码是
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);
}
}
我收到此行错误$ this-> PropertyPlan-> save($ ppinsertdata);
如何避免在此场景中调用afterSave()
请帮我解决这个问题......
答案 0 :(得分:1)
试试这个 -
$this->PropertyPlan->save($ppinsertdata, array('callbacks' => false)); //for disabling all callbacks
阅读本文 -
callbacks Set to false to disable callbacks. Using ‘before’ or ‘after’ will enable only those callbacks
save() - cakephp