搜索
系统检测到您的用户名不符合规范:

toArray 出错求助

浏览:4068 发布日期:2017年02月15日 分类:ThinkPHP5专区
User表中有一个字段 'create_time',类型是 DATETIME 值是 '2017年02月15日 12:37:29' 大概在这块地方出错了, toArray() 方法调用了 date() 方法,传入字符串作为第二个参数,导致格式不对(要求 Unix 时间戳)。
这个转换是 toArray() 方法自己调用的,我使用 DATETIME 保存时间,是否就必然会出错了,这是框架错误,还是我哪里没设置好?

代码:$mUser = Loader::model('User');
$user = $mUser->get(1)->toArray();
执行 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
求助这是什么原因?
最佳答案
评论() 相关
后面还有条评论,
评论支持使用[code][/code]标签添加代码
您需要登录后才可以评论 登录 | 立即注册
收藏
dclchj
积分:2138 等级:LV3
热点推荐
(追記) (追記ここまで)
最新更新

我们

合作

网站

信息

ThinkPHP 是一个免费开源的,快速、简单的面向对象的 轻量级PHP开发框架 ,创立于2006年初,遵循Apache2开源协议发布,是为了敏捷WEB应用开发和简化企业应用开发而诞生的。ThinkPHP从诞生以来一直秉承简洁实用的设计原则,在保持出色的性能和至简的代码的同时,也注重易用性。并且拥有众多的原创功能和特性,在社区团队的积极参与下,在易用性、扩展性和性能方面不断优化和改进,已经成长为国内最领先和最具影响力的WEB应用开发框架,众多的典型案例确保可以稳定用于商业以及门户级的开发。

AltStyle によって変換されたページ (->オリジナル) /