TP5:使用toArray() 出现“A non well formed numeric value encountered”
作者:
秒速五厘米
User表中有一个字段 'create_time',类型是 DATETIME 值是 '2017-02-15 12:37:29' 大概在这块地方出错了, toArray() 方法调用了 date() 方法,传入字符串作为第二个参数,导致格式不对(要求 Unix 时间戳)。
这个转换是 toArray() 方法自己调用的,我使用 DATETIME 保存时间,是否就必然会出错了,这是框架错误,还是我哪里没设置好?
$mUser = Loader::model('User'); $user = $mUser->get(1)->toArray();
[8] ErrorException in Model.php line 354 A non well formed numeric value encountered * @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) { $time = date($format, $time); } return $time; } /** * 数据写入 类型转换 * @access public * @param mixed $value 值 * @param string|array $type 要转换的类型 Call Stack in Model.php line 354 at Error::appError(8, 'A non well formed nu...', 'C:\wamp64\www\tshop\...', 354, ['time' => '2017-02-15 12:37:29', 'format' => 'Y-m-d H:i:s', 'timestamp' => false]) at date('Y-m-d H:i:s', '2017-02-15 12:37:29') in Model.php line 354 at Model->formatDateTime('2017-02-15 12:37:29', 'Y-m-d H:i:s') in Model.php line 449 at Model->getAttr('create_time') in Model.php line 678 at Model->toArray() in User.php line 44 at User->regist() in User.php line 67 at User->toRegist() at ReflectionMethod->invokeArgs(object(User), []) in App.php line 224 at App::invokeMethod([object(User), 'toregist'], []) in App.php line 389 at App::module(['home', 'user', 'toRegist'], ['app_namespace' => 'app', 'app_debug' => true, 'app_trace' => false, ...], true) in App.php line 130 at App::run() in start.php line 18 at require('C:\wamp64\www\tshop\...') in index.php line 17 Exception Datas Error Context time 2017-02-15 12:37:29 format Y-m-d H:i:s timestamp false
解决方案:把application文件下的database.php,配置文件内增加参数 datetime_format 为false做如下修改
//时间字段取出后的默认时间格式 ‘datetime_format’=>false,