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
datetime、date、timestamp
tp5 报 A non well formed numeric value encountered 的错解决办法的更多相关文章
- 安装应用程序 报“ 997 重叠 I/O 操作在进行中”错解决办法
解决办法: 原因: Per Microsoft's blog, patch KB2918614 appears to have caused installation issues 按照微软的博客,补 ...
- 关于TP5模板输出时间戳问题--A non well formed numeric value encountered
某日.因为一个项目.控制器我是这么写的 1 /** 2 * get admin/Picture/index 3 * 显示所有图册信息 4 * @return view 5 */ 6 public fu ...
- 关于PHP Notice: A non well formed numeric value encountered, 你知道多少
---------------------------------------------------------------------------------------------- A non ...
- A non well formed numeric value encountered
在从数据库获取时间戳数据的时候返回的结果是varchar类型 然后在用date("Y-m-d H:i:s", 时间戳)的时候会报错A non well formed numeric ...
- sphinx :undefined reference to `libiconv' 报错解决办法
sphinx :undefined reference to `libiconv' 报错解决办法 2013-11-30 21:45:39 安装sphinx时不停报错...郁闷在make时报错,错误 ...
- MySQL安装过程net start mysql 启动失败 报“错误2,系统找不到文件”的解决办法
MySQL安装过程net start mysql 启动失败 报“错误2,系统找不到文件”的解决办法 错误2,系统找不到文件. 开始...运行... regedit 注册表项: HKEY_LOCAL_ ...
- spring boot jpa 使用update 报错解决办法
在spring boot jpa 中自定义sql,执行update操作报错解决办法: 在@Query(...)上添加 @Modifying@Transactional注解
- Aasible中cryptography兼容性报错解决办法
Aasible中cryptography兼容性报错解决办法 1 Ansible中使用ansible --version查看版本,报错信息如下: ERROR! Unexpected Exception, ...
- sysctl -P 报错解决办法
sysctl -P 报错解决办法问题症状修改 linux 内核文件 #vi /etc/sysctl.conf后执行sysctl -P 报错error: "net.bridge.bridge ...
随机推荐
- File、FileFilter、递归初步
java.io.File 文件和目录 路径名的抽象表示形式 文件:File 存储数据的 目录:Directory 文件夹 用来存储文件 路径:Path 定位具有平台无关性 在任意平台都可以使用 Fil ...
- 操作系统-Windows操作系统的线程调度了解这些
Windows操作系统支持内核级线程,调度单位是线程,它采用基于动态优先级的,抢占式调度,并结合时间配额的调整来完成调度 一.几个前提知识点 就绪线程按优先级进入相应的就绪队列 系统总是选择优先级最高 ...
- Spring 基于xml配置方式的AOP(8)
1.ArithmeticCalculator.java 1 package com.proc; 2 3 public interface ArithmeticCalculator { 4 int ad ...
- springcloud(十六)、feign+hystrix+ribbon+zuul应用案例
在 基于 " sringcloud(十四).ribbon负载均衡策略应用案例 "所有工程的基础上,进行如下操作进行网关设置 1.创建eureka-client-consumer-z ...
- Android开发 GradientDrawable详解
前言 GradientDrawable类似与Xml布局里的shape,常用在一些自己封装的对话框控件的背景或者其他View中,优势是不需要你在带着xml布局文件一起封包.. 画线 GradientDr ...
- leetcode 131 Palindrome Pairs
lc131 Palindrome Pairs 解法1: 递归 观察题目,要求,将原字符串拆成若干子串,且这些子串本身都为Palindrome 那么挑选cut的位置就很有意思,后一次cut可以建立在前一 ...
- Windows相关命令
1.查看端口8080被哪个进程占用 netstat -ano | findstr "8080" 2.查看进程号为5768对应的进程 tasklist | findstr " ...
- synchronized ReentrantLock 比较分析
在编写多线程代码的时候,对于不允许并发的代码,很多需要加锁进行处理.在进行加锁处理时候,synchronized作为java的内置锁,同时也是java关键字,最为被人熟知,即使是最初级的java程序员 ...
- v-bind:class
<!DOCTYPE html> <html lang="zh"> <head> <title></title> < ...
- 密码学笔记(2)——RSA密码
上一篇笔记中讲述了大量的代数知识,这一篇中我们看看如何将这些代数知识应用到RSA密码体制中. 一.公钥密码学简介 在经典密码学的研究模型中,我们根据已选择的秘钥K得到一条加密规则$e_{k}$和一条解 ...