wellnumeric_tp5 报 A non well formed numeric value encountered 的错解决办法

thinkphp5出现A non well formed numeric value encountered的解决办法修改formatDateTime方法如下

默认值:

if (is_null($this->autoWriteTimestamp)) {

// 自动写入时间戳默认false 包含datetime、date、timestamp

$this->autoWriteTimestamp = $this->getQuery()->getConfig('auto_timestamp');//getConfig:获取database.php的配置参数或者convention.php下的database项

}

if (is_null($this->dateFormat)) {

// 设置时间戳格式默认Y-m-d H:i:s

$this->dateFormat = $this->getQuery()->getConfig('datetime_format');

}

if (is_null($this->resultSetType)) {

//数据集返回类型默认array 可选collection(返回collection对象)

$this->resultSetType = $this->getQuery()->getConfig('resultset_type');

}

tp获取器部分逻辑:

存在$this->createTime或者$this->updateTime的情况下

如果$this->autoWriteTimestamp的值是datetime、date、timestamp其中一种则

执行 $value = $this->formatDateTime(strtotime($value), $this->dateFormat);

否则(值为其他情况如true):

$value = $this->formatDateTime($value, $this->dateFormat);

所以要不就关闭自动更新时间 否则formatDateTime方法第一个参数可能会出现两种情况中的一种(时间戳与非时间戳)

/**

* 时间日期字段格式化处理

* @access public

* @param mixed $time 时间日期表达式

* @param mixed $format 日期格式

* @param bool $timestamp 是否进行时间戳转换

* @return mixed

*/

protected function formatDateTime($time, $format, $timestamp = false)

{

if (false !== strpos($format, '\\')) {

$time = new $format($time);

} elseif (!$timestamp && false !== $format) {# !timestamp默认false走这里 设置为date timestap datetime则不走这里

#修改开始位置

if (!preg_match("/^[0-9]{10}|[0-9]{13}$/",$time)) {

$time=strtotime($time);

}#修改结束位置

$time = date($format, $time);

}

return $time;#直接返回

}

或者在模型文件:修改

protected $autoWriteTimestamp=false;         // 是否需要自动写入时

又或者修改datebase.php

'datetime_format' = false

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值