是啊俊

是啊俊

这家伙有点懒,还没写个性签名!

  • 财富值785
  • 威望值20
  • 总积分1115

个人信息

  • 2017-09-22 已签到
    连续签到6天,获得了20个金钱
  • 2017-09-21 已签到
    连续签到5天,获得了20个金钱
  • 回复了 的回答

    yii\db\baseActiveRecord

    public function afterSave($insert, $changedAttributes)
        {
            $this->trigger($insert ? self::EVENT_AFTER_INSERT : self::EVENT_AFTER_UPDATE, new AfterSaveEvent([
                'changedAttributes' => $changedAttributes
            ]));
        }
    

    调用

    protected function updateInternal($attributes = null)
        {
            if (!$this->beforeSave(false)) {
                return false;
            }
            $values = $this->getDirtyAttributes($attributes);
            if (empty($values)) {
                $this->afterSave(false, $values);
                return 0;
            }
            $condition = $this->getOldPrimaryKey(true);
            $lock = $this->optimisticLock();
            if ($lock !== null) {
                $values[$lock] = $this->$lock + 1;
                $condition[$lock] = $this->$lock;
            }
            // We do not check the return value of updateAll() because it's possible
            // that the UPDATE statement doesn't change anything and thus returns 0.
            $rows = static::updateAll($values, $condition);
    
            if ($lock !== null && !$rows) {
                throw new StaleObjectException('The object being updated is outdated.');
            }
    
            if (isset($values[$lock])) {
                $this->$lock = $values[$lock];
            }
    
            $changedAttributes = [];
            foreach ($values as $name => $value) {
                $changedAttributes[$name] = isset($this->_oldAttributes[$name]) ? $this->_oldAttributes[$name] : null;
                $this->_oldAttributes[$name] = $value;
            }
            $this->afterSave(false, $changedAttributes);
    
            return $rows;
        }
    

    谢谢,我问的是这些事件绑定的地方,不是触发的地方,也就是类似:$this->on(self::EVENT_AFTER_INSERT, ...),不知道在哪里写 的

  • 回复了 的回答

    好像是在\vendor\yiisoft\yii2\db
    BaseActiveRecord.php 这个文件中

    打错了,是 事件绑定

  • 回复了 的回答

    好像是在\vendor\yiisoft\yii2\db
    BaseActiveRecord.php 这个文件中

    并没有,这个文件中值看到这些事件名称常量的声明,和事件的触发,并没有看到时间的绑定。。

  • 提出了问题
    ActiveRecord的事件是在哪里注册的
  • 2017-09-20 已签到
    连续签到4天,获得了20个金钱
  • 2017-09-19 已签到
    连续签到3天,获得了15个金钱
  • 2017-09-18 已签到
    连续签到2天,获得了10个金钱
  • 2017-09-17 已签到
    连续签到1天,获得了5个金钱
经理 等级规则
1115/2000
资料完整度
10/100
用户活跃度
0/100

Ta的关注

5

Ta的粉丝

0

Ta的访客

6