yii2 将项目换到阿里云之后,报错
beforeSave() should be compatible with yii\db\BaseActiveRecord::beforeSave($insert)
之前是放到其他服务器,没有这个错误,检查是父类方法需要参数传递,而我定义的没有传递。所以补全即可。
如果又遇到这种问题的,补全就ok了
/** This is invoked before the record is saved.
* @return boolean whether the record should be saved.
*/
public function beforeSave($insert)
{
if(parent::beforeSave($insert))
{
if($this->isNewRecord)
{
$this->create_time=date("Y-m-d H:i:s",time());
$this->author_id=Yii::$app->user->id;
}
return true;
}
else
return false;
}
/**
* This is invoked after the record is saved.
*/
public function afterSave($insert, $changedAttributes)
{
parent::afterSave($insert, $changedAttributes);
Tag::updateFrequency($this->_oldTags, $this->tags,strtolower($this->getClassName()));
}
yii2 beforeSave
最新推荐文章于 2021-03-27 21:43:47 发布