如何在cakephp 3中保存自定义日期时间以创建&改装领域?

时间:2015-09-04 07:13:41

标签: cakephp cakephp-3.0

我正在尝试保存以下数据。但它没有保存日期时间字段。 Created以cakephp方式保存当前日期时间&其他人都是空的。

如何保存自定义日期时间?

提前致谢

foreach ($passwords as $key => $value ) {
    $data['id']             = $collection_id;
    $data['name']           = $value['password'];
    $data['collection_id']  = $collection_id;
    $data['photo_count']    = $value['photos_count'];
    $data['download_count'] = $value['downloaded_users_count'];
    $data['created']        = $value['created'];
    $data['modified']       = $value['modified'];
    $data['expires_at'] = $value['expires_at'];
    $saveData[] = $data;
}

$passwords = $this->Passwords->find('all')->toArray();
$patched = $this->Passwords->patchEntities($passwords, $saveData);
foreach ($patched as $entity) {
    $this->Passwords->save($entity);
}

1 个答案:

答案 0 :(得分:2)

我已经解决了这个问题。只需使用如下 -

        $data['created']        = new Time($value['created']);
        $data['expires_at']     = new Time($value['expires_at']);

要这样做,必须使用它。

use Cake\I18n\Time;