johnny1991

johnny1991

xxxxxxxxxxxxxxxxxxxxx

  • 财富值3285
  • 威望值580
  • 总积分9895

个人信息

  • 回复了 的回答

    源码参考yii\db\baseActiveRecord

    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;
        }
    

    $insert 表示是否是插入,changedAttributes显而易见可以知道,更新的时候被改变的attribute

    $insert = true,表示插入,false,表示更新; 更新的时候,你提交的form表达数据写入到activeRecord对象里面,系统会对比那些字段更改了,那些字段没有更改,把更改过的字段记录下来,就是changeAttributes(不需要你生成),如果不懂,看看源码,源码也很简单的

  • 源码参考yii\db\baseActiveRecord

    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;
        }
    

    $insert 表示是否是插入,changedAttributes显而易见可以知道,更新的时候被改变的attribute

  • 2017-10-07 已签到
    连续签到1天,获得了5个金钱
  • 收藏了教程
    yii2 使用apidoc生成技术文档
  • 2017-09-28 已签到
    连续签到1天,获得了5个金钱
  • 回复了 的回答
    • 是http协议
    • socket是应用层协议和tcp/ip层通信的媒介,所有的应用层协议都是通过socket与tcp/ip通信的
    • socket编程绑定ip地址与port,而没有定义其他的协议,以http为例
    • 首先,http的1,2,3,4,5这些状态是socket没有的
    • 其次,http头部信息里面比如是get,还是post请求,这也是socket没有的
    • 再次,http头部里面的http缓存机制,也是socket所没有
    • 等等,总结一句话,http协议基于socket编程之上又封装了自己的规则,所以所有关于http头部信息都是socket所没有的,其他协议类同

    直接使用socket编程和http没有任何关系的,它使用的tcp/udp协议

  • 回复了 的回答
    • 是http协议
    • socket是应用层协议和tcp/ip层通信的媒介,所有的应用层协议都是通过socket与tcp/ip通信的
    • socket编程绑定ip地址与port,而没有定义其他的协议,以http为例
    • 首先,http的1,2,3,4,5这些状态是socket没有的
    • 其次,http头部信息里面比如是get,还是post请求,这也是socket没有的
    • 再次,http头部里面的http缓存机制,也是socket所没有
    • 等等,总结一句话,http协议基于socket编程之上又封装了自己的规则,所以所有关于http头部信息都是socket所没有的,其他协议类同
  • 回复了 的回答
    • 是http协议
    • socket是应用层协议和tcp/ip层通信的媒介,所有的应用层协议都是通过socket与tcp/ip通信的
    • socket编程绑定ip地址与port,而没有定义其他的协议,以http为例
    • 首先,http的1,2,3,4,5这些状态是socket没有的
    • 其次,http头部信息里面比如是get,还是post请求,这也是socket没有的
    • 再次,http头部里面的http缓存机制,也是socket所没有
    • 等等,总结一句话,http协议基于socket编程之上又封装了自己的规则,所以所有关于http头部信息都是socket所没有的,其他协议类同

    http基于tcp,理论上来说应该是长连接,正常情况下http协议每次请求网页的时候,一次就可把数据加载全,所以结束的时候就已经发送fin请求,连接就结束了;特殊情况下比如网站上播放视频,就是http长连接

    • php的socket通常用于client 和webservice交互时候用到
    • nginx/apache作为服务器,底层就是启动了一个socket server的进程,来处理客户端过来的各种需求,然后交由对应的Php程序处理
    • 是http协议
    • socket是应用层协议和tcp/ip层通信的媒介,所有的应用层协议都是通过socket与tcp/ip通信的
    • socket编程绑定ip地址与port,而没有定义其他的协议,以http为例
    • 首先,http的1,2,3,4,5这些状态是socket没有的
    • 其次,http头部信息里面比如是get,还是post请求,这也是socket没有的
    • 再次,http头部里面的http缓存机制,也是socket所没有
    • 等等,总结一句话,http协议基于socket编程之上又封装了自己的规则,所以所有关于http头部信息都是socket所没有的,其他协议类同
副总裁 等级规则
9895/10000
资料完整度
60/100
用户活跃度
0/100

Ta的关注

19

Ta的粉丝

26

Ta的访客

81