當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Table::updateAll方法代碼示例

本文整理匯總了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;
 }
開發者ID:ripzappa0924,項目名稱:carte0.0.1,代碼行數:26,代碼來源:TreeBehavior.php

示例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);
 }
開發者ID:jdaosavanh,項目名稱:clickerwebapp,代碼行數:16,代碼來源:TableTest.php


注:本文中的Cake\ORM\Table::updateAll方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。