Cake\Controller\Controller::paginate PHP Method

paginate() public method

Will load the referenced Table object, and have the PaginatorComponent paginate the query using the request date and settings defined in $this->paginate. This method will also make the PaginatorHelper available in the view.
public paginate ( Table | string | Query | null $object = null, array $settings = [] ) : Cake\ORM\ResultSet
$object Cake\ORM\Table | string | Cake\ORM\Query | null Table to paginate (e.g: Table instance, 'TableName' or a Query object)
$settings array The settings/configuration used for pagination.
return Cake\ORM\ResultSet Query results
    public function paginate($object = null, array $settings = [])
    {
        if (is_object($object)) {
            $table = $object;
        }
        if (is_string($object) || $object === null) {
            $try = [$object, $this->modelClass];
            foreach ($try as $tableName) {
                if (empty($tableName)) {
                    continue;
                }
                $table = $this->loadModel($tableName);
                break;
            }
        }
        $this->loadComponent('Paginator');
        if (empty($table)) {
            throw new RuntimeException('Unable to locate an object compatible with paginate.');
        }
        $settings = $settings + $this->paginate;
        return $this->Paginator->paginate($table, $settings);
    }

Usage Example

 /**
  * @return void
  */
 public function testPaginate()
 {
     Configure::write('Paginator.limit', 2);
     $ToolsUser = TableRegistry::get('ToolsUsers');
     $count = $ToolsUser->find('count');
     $this->assertTrue($count > 3);
     $this->Controller->loadModel('ToolsUsers');
     $result = $this->Controller->paginate('ToolsUsers');
     $this->assertSame(2, count($result->toArray()));
 }
All Usage Examples Of Cake\Controller\Controller::paginate