{"record":{"id":"10a96d909940f2c1","repo":"cakephp/cakephp","slug":"you-must-set-a-pagination-instance-using-setpaginated-first","errorCode":null,"errorMessage":"You must set a pagination instance using `setPaginated()` first","messagePattern":"You must set a pagination instance using `setPaginated\\(\\)` first","errorType":"exception","errorClass":"CakeException","httpStatus":null,"severity":"error","filePath":"src/View/Helper/PaginatorHelper.php","lineNumber":156,"sourceCode":"\n    /**\n     * Get pagination instance.\n     *\n     * @return \\Cake\\Datasource\\Paging\\PaginatedInterface<array-key, mixed>\n     */\n    protected function paginated(): PaginatedInterface\n    {\n        if (!isset($this->paginated)) {\n            foreach ($this->_View->getVars() as $name) {\n                $value = $this->_View->get($name);\n                if ($value instanceof PaginatedInterface) {\n                    $this->paginated = $value;\n                }\n            }\n        }\n\n        if (!isset($this->paginated)) {\n            throw new CakeException('You must set a pagination instance using `setPaginated()` first');\n        }\n\n        return $this->paginated;\n    }\n\n    /**\n     * Gets the current paging parameters from the result set for the given model\n     *\n     * @return array The array of paging parameters for the paginated result set.\n     */\n    public function params(): array\n    {\n        return $this->getConfig('params') + $this->paginated()->pagingParams();\n    }\n\n    /**\n     * Convenience access to any of the paginator params.\n     *","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/cakephp/cakephp/blob/1128eba9b09f1946df684811350e26f2cef68fac/src/View/Helper/PaginatorHelper.php#L138-L174","documentation":"PaginatorHelper methods that read pagination metadata (params, current, total, links, prev/next checks) require a PaginatedInterface instance to have been injected via setPaginated(). If none was set, the helper's `paginated()` accessor throws a generic CakeException instead of silently returning null.","triggerScenarios":"Calling `$this->Paginator->params()`, `current()`, `total()`, `hasPrev()`, `hasNext()` or `_toggledLink()` in a template/view when setPaginated() was never called — typically because the view was rendered outside a paginated controller action, or the helper was used manually.","commonSituations":"Using PaginatorHelper in a non-paginated template (e.g. an element rendered on a page without a `paginate()` call); using the helper in a console/standalone View; upgrading from CakePHP 3 where request-based paging params were read implicitly.","solutions":["Ensure the controller action calls `$this->paginate($query)` so the Paginated result is set on the request and helper","Call `$this->Paginator->setPaginated($paginatedResult)` explicitly before using any helper methods","Guard template usage with `$this->Paginator->hasPaginated()` (or an isset check) before rendering pagination controls","If pagination is optional in a shared element, render controls only when pagination data exists"],"exampleFix":"// before\n<?= $this->Paginator->total() ?>\n// after\n<?php if ($this->Paginator->hasPaginated()): ?>\n  <?= $this->Paginator->total() ?>\n<?php endif; ?>","handlingStrategy":"validation","validationCode":"if (method_exists($this->Paginator, 'hasPaginated') ? $this->Paginator->hasPaginated() : false) { /* render pagination */ }","typeGuard":null,"tryCatchPattern":"try {\n    $total = $this->Paginator->total();\n} catch (CakeException $e) {\n    $total = 0; // view rendered without pagination\n}","preventionTips":["Only use PaginatorHelper in views rendered from paginated controller actions","Call $this->paginate($query) before rendering templates that page","Use hasPaginated()/isset guards in shared elements"],"tags":["paginator","missing-required-argument","view-state"],"backgroundTag":"invalid-state-transition","analyzedSha":"1128eba9b09f1946df684811350e26f2cef68fac","analyzedAt":"2026-09-12T12:07:00.388Z","contentChangedAt":"2026-09-12T12:07:00.388Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}