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 ...
随机推荐
- HYNB Contest 7:2017 Asia HCMC Vietnam National Programming Contest
A. Another Query on Array Problem B. Board Covering C. Cumulative Sums 题意 \(A_1=1,A_i=A_{i-1}+sod(A_ ...
- 复杂Linq语句写法
从网上收藏的复杂Linq语句写法 1.case when: 原型: sql原型: SELECT ProductID, Name, Color, CASE WHEN Color = 'Red' THEN ...
- webpack 简单笔记(二)CommonsChunkPlugin插件
接下来就要使用CommonsChunkPlugin插件 (一)单一入口,模块单一引用,分文件输出,单一入口,模块重复引用,分文件输 main.js代码 require('./static/js/mai ...
- sort的cmp函数
sort的cmp函数只能写return a>b;或者return a<b;
- LUOGU P2949 [USACO09OPEN]工作调度Work Scheduling (贪心)
解题思路 明明一道比较简单的贪心结果挂了好几次23333,就是按照时间排序,然后拿一个小根堆维护放进去的,如果时间允许就入队并且记录答案.如果不允许就从堆里拿一个最小的比较. #include< ...
- VS2010-MFC(对话框:创建对话框类和添加控件变量)
转自:http://www.jizhuomi.com/software/153.html 前两讲中讲解了如何创建对话框资源.创建好对话框资源后要做的就是生成对话框类了.生成对话框类主要包括新建对话框类 ...
- SpringBoot学习笔记(三):SpringBoot集成Mybatis、SpringBoot事务管理、SpringBoot多数据源
SpringBoot集成Mybatis 第一步我们需要在pom.xml里面引入mybatis相关的jar包 <dependency> <groupId>org.mybatis. ...
- JDK源码阅读--String
public final class String implements java.io.Serializable, Comparable<String>, CharSequence St ...
- 操作系统命令工具Util
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.i ...
- JS实用插件
1. jQuery鼠标滚轮事件插件Mouse Wheel 下载链接:https://github.com/brandonaaron/jquery-mousewheel/ 使用方法: // using ...