yii2 beforeSave

来源:互联网 发布:日程任务软件 编辑:程序博客网 时间:2024/05/16 00:27
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()));    }

0 0
原创粉丝点击