CakePHP, PHP

How to enable Paginator in CakePHP 3

Let’s see how can we enable and initialize the CakePHP built-in Paginator Component so we can use it in our views.

class MyController extends AppController
{
    //Loading Templates from a File
    //This will load the file located at config/paginator-templates.php
    public $helpers = [
        'Paginator' => ['templates' => 'paginator-templates']
    ];
 
    //Define the default query conditions pagination
    public $paginate = [
        'limit' => 25,  //results per page
        'order' => [
            'online' => 'desc'  //default order by 
        ],
        'sortWhitelist' => [
            'online', 'customerid', 'ip', 'username', //fields that can be sorted 
        ]
    ];
 
    public function initialize() 
    {
        parent::initialize();
        $this->loadComponent('Paginator');  //load Paginator Component
    }
}

For more visit Pagination and Paginator pages.