lithium\data\model\Query::page PHP Method

page() public method

Set and get method for page, in relation to limit, of which records to get
public page ( integer | null $page = null ) : integer | lithium\data\Query
$page integer | null
return integer | lithium\data\Query
    public function page($page = null)
    {
        if ($page) {
            $this->_config['page'] = $page = (int) $page ?: 1;
            $this->offset(($page - 1) * $this->_config['limit']);
            return $this;
        }
        return $this->_config['page'];
    }

Usage Example

Example #1
0
 public function testPagination()
 {
     $query = new Query(array('limit' => 5, 'page' => 1));
     $this->assertEqual(0, $query->offset());
     $query = new Query(array('limit' => 5, 'page' => 2));
     $this->assertEqual(5, $query->offset());
     $query->page(1);
     $this->assertEqual(0, $query->offset());
 }