johnny1991
- johnny1991 回复了 johnny1991 的回答
源码参考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
@Allener $insert = true,表示插入,false,表示更新; 更新的时候,你提交的form表达数据写入到activeRecord对象里面,系统会对比那些字段更改了,那些字段没有更改,把更改过的字段记录下来,就是changeAttributes(不需要你生成),如果不懂,看看源码,源码也很简单的
- johnny1991 回答了问题 请教一个afterSave的问题
源码参考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
- johnny1991 2017-10-07 已签到连续签到1天,获得了5个金钱
- johnny1991 2017-09-28 已签到连续签到1天,获得了5个金钱
- johnny1991 回复了 johnny1991 的回答
- 是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所没有的,其他协议类同
@xyf90314 直接使用socket编程和http没有任何关系的,它使用的tcp/udp协议
- johnny1991 回复了 johnny1991 的回答
- 是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所没有的,其他协议类同
- johnny1991 回复了 johnny1991 的回答
- 是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所没有的,其他协议类同
@xyf90314 http基于tcp,理论上来说应该是长连接,正常情况下http协议每次请求网页的时候,一次就可把数据加载全,所以结束的时候就已经发送fin请求,连接就结束了;特殊情况下比如网站上播放视频,就是http长连接
- johnny1991 回答了问题 php socket何时使用
- php的socket通常用于client 和webservice交互时候用到
- nginx/apache作为服务器,底层就是启动了一个socket server的进程,来处理客户端过来的各种需求,然后交由对应的Php程序处理
- johnny1991 回答了问题 TCP/IP协议族图的疑问?
- 是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所没有的,其他协议类同