Cakephp3 / PHP72 Paginator, параметр должен быть массивом или объектом, который реализует счетное - PullRequest
0 голосов
/ 02 июля 2018

После миграции с php5.6 на php7.2 классическая строка переходит к этой ошибке

$books = $this->paginate($query, ['limit' => 10]);

Я прочитал о первом использовании ->toList() перед использованием count(), но в этом случае ... Любая идея, как я могу решить это? Я использую CakePHP 3.4.7.

PS: в моем коде нет функции count (), возможно, внутри страницы.

$conditions = [];
$query = $this->Books->find('all')
            ->contain(['Autors', 'Titles', 'Edituras'])
            ->order(['Books.id' => 'asc']);
if(!empty($conditions)){
    $query->where(['OR' => $conditions]);
} else {
    if(isset($this->request->params['?']['page'])){
        $query->where([]);
    } else {
        $query->where(['1=2']);
    }
}
$this->set('books', $this->paginate($query, ['limit' => 10]));

По умолчанию $ condition пуст и журнал ошибок указывает на последнюю строку

журнал ошибок:

2018-07-02 06:08:51 Warning: Warning (2): count() [<a href='http://php.net/function.count'>function.count</a>]: Parameter must be an array or an object that implements Countable
Request URL: /
Client IP: 81.196.46.249
Trace:
Cake\Error\BaseErrorHandler::handleError() - CORE/src/Error/BaseErrorHandler.php, line 153 
count - [internal], line ??
BCake\Database\QueryCompiler::Cake\Database\{closure}() - CORE/src/Database/QueryCompiler.php, line 128
Cake\Database\Query::traverse() - CORE/src/Database/Query.php, line 311
Cake\Database\QueryCompiler::compile() - CORE/src/Database/QueryCompiler.php, line 99
Cake\Database\Driver::compileQuery() - CORE/src/Database/Driver.php, line 359
Cake\Database\Connection::compileQuery() - CORE/src/Database/Connection.php, line 299
Cake\Database\Query::sql() - CORE/src/Database/Query.php, line 282
Cake\ORM\Query::sql() - CORE/src/ORM/Query.php, line 992
Cake\Database\Driver\Mysql::prepare() - CORE/src/Database/Driver/Mysql.php, line 136
Cake\Database\Connection::prepare() - CORE/src/Database/Connection.php, line 258
Cake\Database\Connection::run() - CORE/src/Database/Connection.php, line 311
Cake\Database\Query::execute() - CORE/src/Database/Query.php, line 213
Cake\ORM\Query::_execute() - CORE/src/ORM/Query.php, line 1011
Cake\ORM\Query::_all() - CORE/src/Datasource/QueryTrait.php, line 276
Cake\ORM\Query::all() - CORE/src/ORM/Query.php, line 960
Cake\Controller\Component\PaginatorComponent::paginate() - CORE/src/Controller/Component/PaginatorComponent.php, line 190
Cake\Controller\Controller::paginate() - CORE/src/Controller/Controller.php, line 717
App\Controller\BooksController::index() - APP/Controller/BooksController.php, line 99
Cake\Controller\Controller::invokeAction() - CORE/src/Controller/Controller.php, line 440
Cake\Http\ActionDispatcher::_invoke() - CORE/src/Http/ActionDispatcher.php, line 119
Cake\Http\ActionDispatcher::dispatch() - CORE/src/Http/ActionDispatcher.php, line 93
Cake\Http\BaseApplication::__invoke() - CORE/src/Http/BaseApplication.php, line 78
Cake\Http\Runner::__invoke() - CORE/src/Http/Runner.php, line 65
Cake\Routing\Middleware\RoutingMiddleware::__invoke() - CORE/src/Routing/Middleware/RoutingMiddleware.php, line 59
Cake\Http\Runner::__invoke() - CORE/src/Http/Runner.php, line 65
Cake\Routing\Middleware\AssetMiddleware::__invoke() - CORE/src/Routing/Middleware/AssetMiddleware.php, line 88
Cake\Http\Runner::__invoke() - CORE/src/Http/Runner.php, line 65
Cake\Error\Middleware\ErrorHandlerMiddleware::__invoke() - CORE/src/Error/Middleware/ErrorHandlerMiddleware.php, line 92
Cake\Http\Runner::__invoke() - CORE/src/Http/Runner.php, line 65
DebugKit\Middleware\DebugKitMiddleware::__invoke() - ROOT/vendor/cakephp/debug_kit/src/Middleware/DebugKitMiddleware.php, line 52
Cake\Http\Runner::__invoke() - CORE/src/Http/Runner.php, line 65
Cake\Http\Runner::run() - CORE/src/Http/Runner.php, line 51
Cake\Http\Server::run() - CORE/src/Http/Server.php, line 80
[main] - ROOT/webroot/index.php, line 37
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...