本文整理汇总了PHP中Cake\ORM\Table::updateAll方法的典型用法代码示例。如果您正苦于以下问题:PHP Table::updateAll方法的具体用法?PHP Table::updateAll怎么用?PHP Table::updateAll使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\ORM\Table
的用法示例。
在下文中一共展示了Table::updateAll方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _recoverTree
/**
* Recursive method used to recover a single level of the tree
*
* @param int $counter The Last left column value that was assigned
* @param mixed $parentId the parent id of the level to be recovered
* @return int Ne next value to use for the left column
*/
protected function _recoverTree($counter = 0, $parentId = null)
{
$config = $this->config();
list($parent, $left, $right) = [$config['parent'], $config['left'], $config['right']];
$pk = (array) $this->_table->primaryKey();
$query = $this->_scope($this->_table->query())->select($pk)->where(function ($exp) use($parentId, $parent) {
return $parentId === null ? $exp->isNull($parent) : $exp->eq($parent, $parentId);
})->order($pk)->hydrate(false)->bufferResults(false);
$leftCounter = $counter;
foreach ($query as $row) {
$counter++;
$counter = $this->_recoverTree($counter, $row[$pk[0]]);
}
if ($parentId === null) {
return $counter;
}
$this->_table->updateAll([$left => $leftCounter, $right => $counter + 1], [$pk[0] => $parentId]);
return $counter + 1;
}
示例2: testUpdateAll
/**
* Test basic multi row updates.
*
* @return void
*/
public function testUpdateAll()
{
$table = new Table(['table' => 'users', 'connection' => $this->connection]);
$fields = ['username' => 'mark'];
$result = $table->updateAll($fields, ['id <' => 4]);
$this->assertSame(3, $result);
$result = $table->find('all')->select(['username'])->order(['id' => 'asc'])->hydrate(false)->toArray();
$expected = array_fill(0, 3, $fields);
$expected[] = ['username' => 'garrett'];
$this->assertEquals($expected, $result);
}