offset() public method

Set and get method for query's offset, i.e. which records to get
public offset ( integer | null $offset = null ) : integer | lithium\data\Query
$offset integer | null
return integer | lithium\data\Query
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());
 }
Example #2
0
 /**
  * Returns a LIMIT statement from the given limit and the offset of the context object.
  *
  * @param integer $limit
  * @param \lithium\data\model\Query $context
  * @return string
  */
 public function limit($limit, $context)
 {
     if (!$limit) {
         return;
     }
     if ($offset = $context->offset() ?: '') {
         $offset = " OFFSET {$offset}";
     }
     return "LIMIT {$limit}{$offset}";
 }