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


PHP TableGateway::getLastInsertValue方法代码示例

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


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

示例1: create

 /**
  * Create a resource
  *
  * @param  mixed $data
  * @return ApiProblem|mixed
  */
 public function create($data)
 {
     $entity = new ClienteEntity();
     $data = json_decode(json_encode($data), true);
     $entity->exchangeArray($data);
     $data = $entity->getArrayCopy();
     $this->tableGateway->insert($data);
     $data['id'] = $this->tableGateway->getLastInsertValue();
     return $data;
 }
开发者ID:siwane,项目名称:tutorial-angularjs-apigility-crud,代码行数:16,代码来源:ClienteResource.php

示例2: create

 /**
  * @param array $data
  * @return object
  */
 public function create(array $data)
 {
     $this->table->insert($data);
     $id = $this->table->getLastInsertValue();
     $entity = $this->find($id);
     if (!$entity) {
         throw new \Exception("Entity not created?");
     }
     return $entity;
 }
开发者ID:kapitchi,项目名称:kap-apigility,代码行数:14,代码来源:DbEntityRepository.php

示例3: persist

 /**
  * @param AbstractEntity $entity
  * @return $this
  */
 public function persist(AbstractEntity $entity)
 {
     $data = $this->hydrator->extract($entity);
     if ($this->hasIdentity($entity)) {
         $this->gateway->update($data, ['id' => $entity->getId()]);
     } else {
         $this->gateway->insert($data);
         $entity->setId($this->gateway->getLastInsertValue());
     }
     return $this;
 }
开发者ID:nathanphan,项目名称:cleanphp-example,代码行数:15,代码来源:AbstractDataTable.php

示例4: internalSave

 /**
  * @param AbstractModel $model
  */
 protected function internalSave(AbstractModel $model)
 {
     $pKey = $this->getPrimaryKey();
     if (isset($model->id)) {
         $this->tableGateway->update($model->toArray(), [$pKey => $model->{$pKey}]);
     } else {
         $this->tableGateway->insert($model->toArray());
         $id = $this->tableGateway->getLastInsertValue();
         $model->{$pKey} = $id;
     }
 }
开发者ID:jeremygiberson,项目名称:what-changed,代码行数:14,代码来源:AbstractMapper.php

示例5: insertNode

 /**
  * Insert node
  *
  * @param integer $level
  * @param integer $nearKey
  * @param array $data
  * @param array $filter
  * @param boolean $useTransaction
  * @return integer|string
  */
 protected function insertNode($level, $nearKey, array $data, array $filter = [], $useTransaction = true)
 {
     try {
         if ($useTransaction) {
             $this->tableGateway->getAdapter()->getDriver()->getConnection()->beginTransaction();
         }
         $this->tableGateway->update([$this->left => new Expression('IF (' . $this->left . ' > ?, ' . $this->left . ' + 2, ' . $this->left . ')', [$nearKey]), $this->right => new Expression('IF (' . $this->right . '  > ?, ' . $this->right . ' + 2, ' . $this->right . ')', [$nearKey])], [(new Predicate())->greaterThanOrEqualTo($this->right, $nearKey)] + $filter);
         $leftKey = $nearKey + 1;
         $rightKey = $nearKey + 2;
         $level = $level + 1;
         // insert a new node
         $this->tableGateway->insert([$this->left => $leftKey, $this->right => $rightKey, $this->level => $level] + $data);
         $insertId = $this->tableGateway->getLastInsertValue();
         // update parent info
         if (false !== ($parent = $this->getParentNode($leftKey, $rightKey, $level, $filter))) {
             $this->tableGateway->update([$this->parent => $parent[$this->nodeId]], [$this->nodeId => $insertId]);
         }
         if ($useTransaction) {
             $this->tableGateway->getAdapter()->getDriver()->getConnection()->commit();
         }
     } catch (Exception $e) {
         if ($useTransaction) {
             $this->tableGateway->getAdapter()->getDriver()->getConnection()->rollback();
         }
         ApplicationErrorLogger::log($e);
         return $e->getMessage();
     }
     return $insertId;
 }
开发者ID:esase,项目名称:dream-cms,代码行数:39,代码来源:ApplicationAbstractNestedSet.php

示例6: indexAction

 /**
  * Create easypay trade.
  * @see \Zend\Mvc\Controller\AbstractActionController::indexAction()
  */
 public function indexAction()
 {
     if ($this->verifyRequest()) {
         $this->appendTitle('收银台');
         $this->layout()->setVariable('is_cashier_page', true);
         $dbAdapter = $this->getServiceLocator()->get('Zend\\Db\\Adapter\\Adapter');
         /**
          * Check the parameters if they are valid.
          */
         $parameters = $this->getRequest()->getQuery();
         // if merchant exsist
         // if trade|redirect_url|notify_url|sign empty
         // if price is a floating numberic
         $exception = new \Exception('Parameters is invalid!');
         if (empty(trim($parameters['trade'])) || empty(trim($parameters['redirect_url'])) || empty(trim($parameters['notify_url'])) || empty(trim($parameters['sign']))) {
             throw $exception;
         }
         if (!is_numeric(trim($parameters['price']))) {
             throw $exception;
         }
         $merchant_validator = new \Zend\Validator\Db\NoRecordExists(array('table' => 'merchant', 'field' => 'name', 'adapter' => $dbAdapter));
         if ($merchant_validator->isValid(intval($parameters['merchant']))) {
             throw $exception;
         }
         /**
          * Check if there is an exsist trade.
          */
         $GetMerchantIdByName = $this->getServiceLocator()->get('GetMerchantIdByName');
         $merchant_id = $GetMerchantIdByName($parameters['merchant']);
         $trade = $this->getTrade($merchant_id, trim($parameters['trade']));
         $trade_id = null;
         $payment_interface_type = null;
         if (!empty($trade)) {
             // Trade exsist.
             if ($trade->pay_status) {
                 throw new \Exception('Trade had payed before!');
             } else {
                 // Update the exsist trade
                 $trade->price = trim($parameters['price']);
                 $trade->redirect_url = trim($parameters['redirect_url']);
                 $trade->notify_url = trim($parameters['notify_url']);
                 $trade->save();
                 $trade_id = $trade->id;
                 $payment_interface_type = $trade->payment_interface_type;
             }
         } else {
             // Trade not exsist.
             // Create a new trade
             $tableGateway = new TableGateway('trade', $dbAdapter, new Feature\RowGatewayFeature('id'));
             $tableGateway->insert(array('merchant_id' => $merchant_id, 'merchant_trade_id' => trim($parameters['trade']), 'redirect_url' => trim($parameters['redirect_url']), 'notify_url' => trim($parameters['notify_url']), 'price' => trim($parameters['price']), 'pay_status' => 0, 'create_time' => date('Y-n-j H:i:s', time())));
             $trade_id = $tableGateway->getLastInsertValue();
         }
         return array('price' => trim($parameters['price']), 'merchant' => $parameters['merchant'], 'trade' => trim($parameters['trade']), 'selected_payment' => $payment_interface_type);
     } else {
         throw new \Exception('Bad Reaquest !');
     }
 }
开发者ID:lpj0017,项目名称:easypay,代码行数:61,代码来源:IndexController.php

示例7: persist

 /**
  * Saves the given rating to the storage system.
  *
  * @param Rating $rating The rating to persist.
  */
 public function persist(Rating $rating)
 {
     if ($rating->getId()) {
         $this->gateway->update(array('typeId' => $rating->getTypeId(), 'userId' => $rating->getUserId(), 'rating' => $rating->getRating()), array('id' => $rating->getId()));
     } else {
         $this->gateway->insert(array('typeId' => $rating->getTypeId(), 'userId' => $rating->getUserId(), 'rating' => $rating->getRating()));
         $id = $this->gateway->getLastInsertValue();
         $rating->setId($id);
     }
 }
开发者ID:waltertamboer,项目名称:wtrating,代码行数:15,代码来源:ZendDbMapper.php

示例8: insert

 /**
  * Adds a data
  */
 public function insert()
 {
     $id = $this->table->insert($this->data);
     if (is_null($id)) {
         if (array_key_exists('firephp', $GLOBALS)) {
             $GLOBALS['firephp']->error('Error on query ' . $this->table->getSql()->getSqlPlatform()->getSqlString($this->table->getAdapter()->getPlatform()));
         }
         throw new Exception('Error on query ' . $this->table->getSql()->getSqlPlatform()->getSqlString($this->table->getAdapter()->getPlatform()));
     }
     $this->data[$this->primary] = $this->table->getLastInsertValue();
 }
开发者ID:caiofior,项目名称:cercaziende,代码行数:14,代码来源:Content.php

示例9: save

 /**
  * Сохраняет объект в таблице
  *
  * @param EntityInterface $object
  * @throws \Exception
  */
 public function save(EntityInterface $object)
 {
     $data = array();
     foreach ($this->fields as $field) {
         $data[$field] = $object->{$field};
     }
     $id = $object->getKeyValue();
     if (null === $id) {
         $this->tableGateway->insert($data);
         $object->{$object->getKeyName()} = $this->tableGateway->getLastInsertValue();
     } else {
         if ($this->getByKey($id, $object->getKeyName())) {
             $this->tableGateway->update($data, array($object->getKeyName() => $id));
         } else {
             throw new \Exception('row with ' . $id . ' id does not exist');
         }
     }
 }
开发者ID:sedpro,项目名称:test_skyeng,代码行数:24,代码来源:Simple.php

示例10: create

 /**
  * {@inheritdoc}
  *
  * {@inheritdoc}
  */
 public function create($itemData, $rewriteIfExist = false)
 {
     $identifier = $this->getIdentifier();
     $adapter = $this->dbTable->getAdapter();
     // begin Transaction
     $errorMsg = 'Can\'t start insert transaction';
     $adapter->getDriver()->getConnection()->beginTransaction();
     try {
         if (isset($itemData[$identifier]) && $rewriteIfExist) {
             $errorMsg = 'Can\'t delete item with "id" = ' . $itemData[$identifier];
             $this->dbTable->delete(array($identifier => $itemData[$identifier]));
         }
         $errorMsg = 'Can\'t insert item';
         $rowsCount = $this->dbTable->insert($itemData);
         $adapter->getDriver()->getConnection()->commit();
     } catch (\Exception $e) {
         $adapter->getDriver()->getConnection()->rollback();
         throw new DataStoresException($errorMsg, 0, $e);
     }
     $id = $this->dbTable->getLastInsertValue();
     $newItem = array_merge(array($identifier => $id), $itemData);
     return $newItem;
 }
开发者ID:avz-cmf,项目名称:zaboy-res,代码行数:28,代码来源:DbTable.php

示例11: _create

 protected function _create($itemData, $rewriteIfExist = false)
 {
     $identifier = $this->getIdentifier();
     if ($rewriteIfExist) {
         if (isset($itemData[$identifier])) {
             $this->deleteIfExist($itemData, $identifier);
         } else {
             if (isset($itemData[0]) && isset($itemData[0][$identifier])) {
                 foreach ($itemData as $item) {
                     $this->deleteIfExist($item, $identifier);
                 }
             }
         }
     }
     $this->dbTable->insert($itemData);
     if (!isset($itemData[$identifier])) {
         $id = $this->dbTable->getLastInsertValue();
         $newItem = $this->read($id);
     } else {
         $newItem = $itemData;
     }
     return $newItem;
 }
开发者ID:avz-cmf,项目名称:zaboy-rest,代码行数:23,代码来源:DbTable.php

示例12: testGetLastInsertValue

 /**
  * @covers Zend\Db\TableGateway\TableGateway::getLastInsertValue
  */
 public function testGetLastInsertValue()
 {
     $this->table->insert(array('foo' => 'bar'));
     $this->assertEquals(10, $this->table->getLastInsertValue());
 }
开发者ID:rikaix,项目名称:zf2,代码行数:8,代码来源:TableGatewayTest.php

示例13: save

 public function save($version)
 {
     $this->tableGateway->insert(['version' => $version]);
     return $this->tableGateway->getLastInsertValue();
 }
开发者ID:t4web,项目名称:migrations,代码行数:5,代码来源:Table.php

示例14: index05Action

 public function index05Action()
 {
     $table = "user";
     $adapter = $this->getServiceLocator()->get("db_books");
     $tableGateway = new TableGateway($table, $adapter);
     $insertObj = new Insert("user");
     $insertObj->columns(array("name", "email"))->values(array("name" => "Armasky", "email" => "ak@hotmail.com"));
     $tableGateway->insertWith($insertObj);
     //last record inserted
     echo $tableGateway->getLastInsertValue();
     return false;
 }
开发者ID:trongle,项目名称:zend-2,代码行数:12,代码来源:TableGatewayController.php

示例15: addSimpleData

 public function addSimpleData($table, $data)
 {
     $tableGateway = new TableGateway($table, $this->dbAdapter);
     $tableGateway->insert($data);
     return $tableGateway->getLastInsertValue();
 }
开发者ID:brighten01,项目名称:zf2-openstack-api,代码行数:6,代码来源:BaseMapper.php


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