避免ORM返回Cake \ I18n \ Time实例

时间:2015-04-22 19:27:20

标签: cakephp-3.0

我的数据库

上有以下数据
  DATE           DATE         TIME
+--------------+------------+----------------+
| initial_date | final_date | expected_hours |
+--------------+------------+----------------+
| 2015-04-20   | 2015-05-24 | 13:00:00       |
| 2015-04-13   | 2015-05-17 | 13:00:00       |
+--------------+------------+----------------+

但是当我打电话时

$this->set('weeks', $this->paginate($this->Weeks));

它会在这3列上返回Cake\I18n\Time个实例,正如here

所示

如何避免此实例?

修改

我想这样做的原因是因为当我44:00:00上有expected_hours之类的内容时,它会失败

DateTime::modify(): Failed to parse time string (44:00:00) at position 0 (4): Un
expected character

仅接受24:00:00或更少...

欢迎任何想法

1 个答案:

答案 0 :(得分:2)

WeeksTable课程中添加以下内容:

use Cake\Database\Schema\Table as Schema;

...
protected function _initializeSchema(Schema $schema)
{
    $schema->columnType('initial_date', 'string');
    $schema->columnType('final_date', 'string');
    $schema->columnType('expected_hours', 'string');

    return $schema;
}

这将迫使架构系统将这些列视为字符串。