Yii在其他模型中调用beforeSave();s beforeSave()
我试图在模型的beforeSave()方法中保存另一个模型的记录。我希望save()方法在foresave()之前调用另一个的模型,但事实并非如此。这是一个bug还是我错过了什么?下面是一些代码 运营模式Yii在其他模型中调用beforeSave();s beforeSave(),yii,Yii,我试图在模型的beforeSave()方法中保存另一个模型的记录。我希望save()方法在foresave()之前调用另一个的模型,但事实并非如此。这是一个bug还是我错过了什么?下面是一些代码 运营模式 public function beforeSave(){ if(parent::beforeSave()){ if($this->isNewRecord){ $this->creation_date=$this->modif
public function beforeSave(){
if(parent::beforeSave()){
if($this->isNewRecord){
$this->creation_date=$this->modification_date=time();
$cur=Currencies::model()->find('LOWER(short)=?',array('usd'));
if($cur->id!=$this->currency_id){
$conv_cours=Currencies::model()->findByPk($this->currency_id);
$this->ammount_usd=round(($this->ammount*$conv_cours->buy)/$cur->sell,4);
}else{
$this->ammount_usd=$this->ammount;
}
}else{
$this->modification_date=time();
}
$opType=OperationType::model()->findByPk($this->operation_type);
$log=new ActionLogs;
$log->comment=Yii::app()->user->name.' добавил '.$opType->name;
/*$log->logtime=time();
$log->user_id=Yii::app()->user->id;*/
$v=1;
$log->save ();
return true;
}else{
return false;
}
}
和另一个模型beforeSave()
}
谢谢 我能想到的Yii在尝试保存activerecord时不调用beforeSave的唯一原因是它的验证失败。在save调用后尝试转储$object->errors,或者尝试使用$object->save(FALSE)保存以跳过验证。这样我们就可以消除这个原因。谢谢,我不知道如何在save()方法中传递参数。
public function beforeSave(){
if(parent::beforeSave()){
if($this->isNewRecord){
$this->logtime=time();
$this->user_id=Yii::app()->user->id;
}
return true;
}else{
return false;
}