我试图将表中任何已删除的行保存在另一个数据库的另一个表中
所以我覆盖了afterDelete
CActiveRecord
方法
像这样
if ($this->hasEventHandler('onAfterDelete')) {
$this->onAfterDelete(new CEvent($this));
}
if(Yii::app()->user->isGuest)
$user_id = 0 ;
else
$user_id = Yii::app()->user->id ;
// this is a method to save the row in different table
$this->setEventLog($user_id,"delete",$this->tableName(),$this->getAttributes());
除了一件事,这对我来说非常好
如果删除位于transaction
且rollback
$transaction = Yii::app()->db->beginTransaction();
$logtest = new mytable ;
$logtest->title = "title 2" ;
$logtest->save() ;
$logtest = new mytable ;
$logtest->title = "title 2" ;
$logtest->save() ;
$transaction->rollback();
它触发afterDelete
并保存行,尽管它甚至没有被删除
如何在afterDelete
方法