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

limit() public method

Set or get the limit for the amount of results to return.
public limit ( integer | boolean $limit = null ) : integer | null | Query
$limit integer | boolean An integer indicating the number of results to limit or `false` to employ no limit at all. Or `null` to retrieve the current limit.
return integer | null | Query Either the currrent limit when $limit is `null` or the query itself when setting the limit or providing `false`.
    public function limit($limit = null)
    {
        if ($limit) {
            $this->_config['limit'] = (int) $limit;
            return $this;
        }
        if ($limit === false) {
            $this->_config['limit'] = null;
            return $this;
        }
        return $this->_config['limit'];
    }

Usage Example

Example #1
0
 public function testLimit()
 {
     $query = new Query($this->_queryArr);
     $expected = 10;
     $result = $query->limit();
     $this->assertEqual($expected, $result);
     $query->limit(5);
     $expected = 5;
     $result = $query->limit();
     $this->assertEqual($expected, $result);
 }