本文整理汇总了PHP中Cake\Database\Query::limit方法的典型用法代码示例。如果您正苦于以下问题:PHP Query::limit方法的具体用法?PHP Query::limit怎么用?PHP Query::limit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Database\Query
的用法示例。
在下文中一共展示了Query::limit方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: findCursor
public function findCursor(Query $query)
{
$current = $this->request->query('cursor');
$limit = $this->request->query('limit') ?: 10;
if ($current) {
$query->where(['id >' => $current]);
}
$query->limit($limit);
return $query;
}
示例2: testSelectOffset
/**
* Tests selecting rows combining a limit and offset clause
*
* @return void
*/
public function testSelectOffset()
{
$query = new Query($this->connection);
$result = $query->select('id')->from('comments')->limit(1)->offset(0)->order(['id' => 'ASC'])->execute();
$this->assertCount(1, $result);
$this->assertEquals(['id' => 1], $result->fetch('assoc'));
$query = new Query($this->connection);
$result = $query->select('id')->from('comments')->limit(1)->offset(1)->execute();
$this->assertCount(1, $result);
$this->assertEquals(['id' => 2], $result->fetch('assoc'));
$query = new Query($this->connection);
$result = $query->select('id')->from('comments')->limit(1)->offset(2)->execute();
$this->assertCount(1, $result);
$this->assertEquals(['id' => 3], $result->fetch('assoc'));
$query = new Query($this->connection);
$result = $query->select('id')->from('articles')->order(['id' => 'DESC'])->limit(1)->offset(0)->execute();
$this->assertCount(1, $result);
$this->assertEquals(['id' => 3], $result->fetch('assoc'));
$result = $query->limit(2)->offset(1)->execute();
$this->assertCount(2, $result);
$this->assertEquals(['id' => 2], $result->fetch('assoc'));
$this->assertEquals(['id' => 1], $result->fetch('assoc'));
}
示例3: testSelectOffset
/**
* Tests selecting rows combining a limit and offset clause
*
* @return void
*/
public function testSelectOffset()
{
$this->loadFixtures('Articles', 'Comments');
$query = new Query($this->connection);
$result = $query->select('id')->from('comments')->limit(1)->offset(0)->order(['id' => 'ASC'])->execute();
$this->assertCount(1, $result);
$this->assertEquals(['id' => 1], $result->fetch('assoc'));
$query = new Query($this->connection);
$result = $query->select('id')->from('comments')->limit(1)->offset(1)->execute();
$this->assertCount(1, $result);
$this->assertEquals(['id' => 2], $result->fetch('assoc'));
$query = new Query($this->connection);
$result = $query->select('id')->from('comments')->limit(1)->offset(2)->execute();
$this->assertCount(1, $result);
$this->assertEquals(['id' => 3], $result->fetch('assoc'));
$query = new Query($this->connection);
$result = $query->select('id')->from('articles')->order(['id' => 'DESC'])->limit(1)->offset(0)->execute();
$this->assertCount(1, $result);
$this->assertEquals(['id' => 3], $result->fetch('assoc'));
$result = $query->limit(2)->offset(1)->execute();
$this->assertCount(2, $result);
$this->assertEquals(['id' => 2], $result->fetch('assoc'));
$this->assertEquals(['id' => 1], $result->fetch('assoc'));
$query = new Query($this->connection);
$query->select('id')->from('comments')->limit(1)->offset(1)->execute();
$dirty = $this->readAttribute($query, '_dirty');
$this->assertFalse($dirty);
$query->offset(2);
$dirty = $this->readAttribute($query, '_dirty');
$this->assertTrue($dirty);
}