在CakePHP 3中查询两个日期之间的记录时出现错误“在数组上调用成员函数format()”

时间:2018-11-20 14:40:14

标签: cakephp cakephp-3.0 cakephp-3.x cakephp-3.5

我想查找两个日期之间的记录,所以我编写了这段代码:

$this->paginate['conditions']['OR']['Clients.date_registered BETWEEN ? and ?'] = [$dateRegFrom, $dateRegTo];

date_registereddatetime列,所以我尝试了两种格式

即日期('Y-m-d')和日期('Y-m-d H:i:s')

条件就是这样,

[OR] => Array
        (
            [Clients.date_registered BETWEEN ? and ?] => Array
                (
                    [0] => 2017-11-01 00:00:00    //2017-11-01 in Y-m-d format
                    [1] => 2018-11-20 22:28:55    //2018-11-20 in Y-m-d format
                )

        )

但是我收到一个错误(详细信息)

file :     "/vendor/cakephp/cakephp/src/Database/Type/DateTimeType.php"
line : 122
message : "Call to a member function format() on array"

如何摆脱这个问题/问题?

1 个答案:

答案 0 :(得分:0)

我已更改代码,并在AND条件中使用了OR条件,

$this->paginate['conditions']['OR'][] = [
                        'Clients.' . $filter['field'] . ' >=' => $dateRegFrom,
                        'Clients.' . $filter['field'] . ' <=' => $dateRegTo,
                    ];