如何避免调用 afterSave for 特定函数在 cakephp 中执行
在模型 I 中具有
公共函数 afterSave() {}
每次使用我需要调用的表单手动插入记录时,我需要调用 afterSave()...
但是当我使用 for 循环插入记录时。 我不想在保存()之后调用
。我的 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->属性计划->保存($ppinsertdata);
如何避免在这种情况下调用 afterSave()
请帮助我解决此解决方案....
试试这个 -
$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