本文整理匯總了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);
}