我无法弄清楚为什么CakePHP会错误地解析我的日期。
$d = new \Cake\I18n\Date('1920-01-20');
debug($d);
如果在代码
中使用,则没问题object(Cake\I18n\Date) {
'time' => '1920-01-20T00:00:00+00:00',
'timezone' => 'UTC',
'fixedNowTime' => false
}
但是当它来自形式(我只是使用文字输入,而不是蛋糕的日期下拉)到patchEntity潜伏着一些魔法(或我的失明)
$member = $this->Members->newEntity();
$member->profiles = [$this->Members->Profiles->newEntity()];
$this->Members->patchEntity($member, [
'username' => 'usern',
'profiles' => [[
'birthdate' => '1920-01-20',
'sex' => 'female']]
]);
debug($member);
这让我发疯了
object(App\Model\Entity\Member) {
'profiles' => [
(int) 0 => object(App\Model\Entity\Profile) {
'birthdate' => object(Cake\I18n\Date) {
'time' => '2179-12-01T00:00:00+00:00',
'timezone' => 'UTC',
'fixedNowTime' => false
},
'sex' => 'female',
'[new]' => true,
'[accessible]' => [
'member_id' => true,
'sex' => true,
'birthdate' => true,
],
'[dirty]' => [
'birthdate' => true,
'sex' => true
],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[invalid]' => [],
'[repository]' => 'Profiles'
}
],
'username' => 'usern',
'[new]' => true,
'[accessible]' => [
'username' => true,
'profiles' => true
],
'[dirty]' => [
'profiles' => true,
'username' => true
],
'[original]' => [
'profiles' => [
(int) 0 => object(App\Model\Entity\Profile) {
'[new]' => true,
'[accessible]' => [
'member_id' => true,
'sex' => true,
'birthdate' => true,
],
'[dirty]' => [],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[invalid]' => [],
'[repository]' => 'Profiles'
}
]
],
'[virtual]' => [],
'[errors]' => [],
'[invalid]' => [],
'[repository]' => 'Members'
}
为什么在地球上变成2179-12-01
?我相信我错过了一些简单的东西,但我已经坚持了几个小时。