当前位置: 首页>>代码示例>>PHP>>正文


PHP Table::connection方法代码示例

本文整理汇总了PHP中Cake\ORM\Table::connection方法的典型用法代码示例。如果您正苦于以下问题:PHP Table::connection方法的具体用法?PHP Table::connection怎么用?PHP Table::connection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cake\ORM\Table的用法示例。


在下文中一共展示了Table::connection方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: moveNode

 /**
  * Move a node under the same parent node or under a new node.
  * New position of the node can be specified
  *
  * @param int $id ID of the node to move
  * @param int $parent_id ID of the (new) parent node
  * @param int $position New position of the node. Position is zero based.
  * @return boolean
  */
 public function moveNode($id, $parent_id, $position = null)
 {
     $primaryKey = $this->_table->schema()->primaryKey();
     $primaryKey = count($primaryKey) == 1 ? $primaryKey[0] : $primaryKey;
     $parent_id_fieldname = $this->config('model_parent_id_fieldname');
     $sort_fieldname = $this->config('model_sort_fieldname');
     $connection = $this->_table->connection();
     $connection->begin();
     $result = true;
     /*
      * Get moved node
      */
     $node = $this->_table->get($id);
     /*
      * Get current nodes positions of (new) siblings
      */
     $current_children = $this->_table->query()->where([$parent_id_fieldname => $parent_id])->order([$sort_fieldname => 'asc']);
     $new_sort_children = [];
     foreach ($current_children as $current_position => $current_child) {
         if ($current_child->{$primaryKey} != $id) {
             $new_sort_children[] = $current_child;
         }
     }
     /*
      * Default position is after all siblings
      */
     $position = isset($position) ? $position : $current_children->count();
     $position = $position >= 0 ? $position : 0;
     $position = $position <= count($new_sort_children) ? $position : count($new_sort_children);
     /*
      * Insert moved node at position
      */
     array_splice($new_sort_children, $position, 0, array($node));
     /*
      * If node has a new parent -> save it
      */
     if ($node->{$parent_id_fieldname} != $parent_id) {
         $query = $this->_table->query()->update()->set([$parent_id_fieldname => $parent_id])->where([$primaryKey => $id]);
         if (!$query->execute()) {
             $result = false;
         }
     }
     /*
      * Update positions
      */
     foreach ($new_sort_children as $index => $new_sort_child) {
         $query = $this->_table->query()->update()->set([$sort_fieldname => $index * 10])->where([$primaryKey => $new_sort_child->{$primaryKey}]);
         if (!$query->execute()) {
             $result = false;
         }
     }
     /***********/
     if ($result) {
         $connection->commit();
     } else {
         $connection->rollback();
     }
     return $result;
 }
开发者ID:alaxos,项目名称:cakephp3-libs,代码行数:68,代码来源:AncestorBehavior.php

示例2: truncateTable

 /**
  * Helper method that clears all records from the provided Table instance.
  *
  * The default file is `config/seed.php`. When the `--dev` flag is
  * present, the default file changes to `config/seed_dev.php`. If
  * the `--file` option is present, it overrides everything else and
  * its value is used explicitly.
  *
  * @param Cake\ORM\Table $Table The Table instance to TRUNCATE.
  * @return bool True on success truncation, false on failure.
  */
 protected function truncateTable($Table)
 {
     $truncateSql = $Table->schema()->truncateSql($Table->connection())[0];
     $success = $Table->connection()->query($truncateSql);
     if ($success) {
         $this->verbose("<success>{$Table->alias()}: Existing DB records truncated.</success>");
     } else {
         $this->quiet("<warning>{$Table->alias()}: Can not truncate existing records.</warning>");
     }
     return $success;
 }
开发者ID:loadsys,项目名称:cakephp-basic-seed,代码行数:22,代码来源:BasicSeedShell.php

示例3: testConnection

 /**
  * Tests connection method
  *
  * @return void
  */
 public function testConnection()
 {
     $table = new Table(['table' => 'users']);
     $this->assertNull($table->connection());
     $table->connection($this->connection);
     $this->assertSame($this->connection, $table->connection());
 }
开发者ID:jdaosavanh,项目名称:clickerwebapp,代码行数:12,代码来源:TableTest.php

示例4: recover

 /**
  * Recovers the lft and right column values out of the hirearchy defined by the
  * parent column.
  *
  * @return void
  */
 public function recover()
 {
     $this->_table->connection()->transactional(function () {
         $this->_recoverTree();
     });
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:12,代码来源:TreeBehavior.php


注:本文中的Cake\ORM\Table::connection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。