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


PHP TableGateway::insert方法代码示例

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


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

示例1: _initObject

 /**
  * This method init $this->object
  */
 protected function _initObject($data = null)
 {
     if (is_null($data)) {
         $data = $this->_itemsArrayDelault;
     }
     $this->_prepareTable($data);
     $this->dbTable->insert($data);
 }
开发者ID:avz-cmf,项目名称:zaboy-rest,代码行数:11,代码来源:DbTableMultiInsertTest.php

示例2: doUpdateModel

 /**
  * {@inheritDoc}
  */
 protected function doUpdateModel($model)
 {
     if ($id = $this->getModelId($model)) {
         $this->tableGateway->update($this->tableGateway->getResultSetPrototype()->getHydrator()->extract($model), array("{$this->idField} = ?" => $id));
     } else {
         $this->tableGateway->insert($this->tableGateway->getResultSetPrototype()->getHydrator()->extract($model));
     }
 }
开发者ID:stan5621,项目名称:eduwind,代码行数:11,代码来源:TableGatewayStorage.php

示例3: create

 /**
  * @param Request $request
  * @param Response $response
  * @param $args
  *
  * @return ResponseInterface
  */
 public function create(Request $request, Response $response, $args)
 {
     try {
         $this->gateway->insert($request->getParsedBody());
         return $response->withJson(["result" => $this->gateway->lastInsertValue]);
     } catch (\Exception $e) {
         return $response->withStatus(400, $e->getMessage());
     }
 }
开发者ID:geggleto,项目名称:slimgateway,代码行数:16,代码来源:EntityController.php

示例4: 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

示例5: 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

示例6: setLock

 /**
  * @param string $key
  * @param DateTime $endDate
  * @return mixed Lock\Handle or false
  */
 public function setLock($key, DateTime $endDate)
 {
     try {
         $result = $this->gateway->insert(['key' => $key, 'end_datetime' => $endDate->format($this->options->getDbDateTimeFormat())]);
         if ($result) {
             return $this->createLockHandle($key);
         }
     } catch (\Exception $e) {
     }
     return false;
 }
开发者ID:beaucal,项目名称:beaucal-long-throttle,代码行数:16,代码来源:Db.php

示例7: 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

示例8: 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

示例9: saveCategory

 public function saveCategory(Category $category)
 {
     $data = array('id_category' => $category->id_category, 'name' => $category->name, 'slug' => $category->slug);
     $id = (int) $category->id_category;
     if ($id == 0) {
         $this->tableGateway->insert($data);
     } elseif ($this->getCategoryById($id)) {
         $this->tableGateway->update($data, array('id_category = ?' => $id));
     } else {
         throw new \Exception('Form id does not exist');
     }
 }
开发者ID:Lebe1ge,项目名称:JobeetForZF2,代码行数:12,代码来源:CategoryTable.php

示例10: saveWarlog

 /**
  * Saves an account to the db. If the id exists the given dataset will be updated
  * @param \Account\Model\Account $account
  *
  * @throws \Exception
  */
 public function saveWarlog(Warlog $warlog)
 {
     $data = ['wins' => $warlog->getWins(), 'losses' => $warlog->getLosses(), 'draws' => $warlog->getDraws()];
     if (!$warlog->getId()) {
         $this->tableGateway->insert($data);
     } else {
         if ($this->getWarlog()) {
             $this->tableGateway->update($data, ['id' => $warlog->getId()]);
         } else {
             throw new \Exception('Account id does not exist');
         }
     }
 }
开发者ID:snowiow,项目名称:eternaldeztiny,代码行数:19,代码来源:WarlogTable.php

示例11: saveNewsCategory

 /**
  * Saves the given NewsCategory object to the db
  *
  *  @param NewsCategory
  *  @throws \Exception
  */
 public function saveNewsCategory(NewsCategory $nc)
 {
     $data = ['name' => $nc->getName()];
     $id = (int) $nc->getId();
     if ($id == 0) {
         $this->tableGateway->insert($data);
     } else {
         if ($this->getNewsCategoryBy(['id' => $id])) {
             $this->tableGateway->update($data, ['id' => $id]);
         } else {
             throw new \Ȩxception('NewsCategory id does not exist');
         }
     }
 }
开发者ID:snowiow,项目名称:eternaldeztiny,代码行数:20,代码来源:NewsCategoryTable.php

示例12: saveWarstatus

 /**
  * Saves the given object ot the db
  * @param Warstatus $warstatus
  * @throws \Exception
  */
 public function saveWarstatus(Warstatus $warstatus)
 {
     $data = $warstatus->getArrayCopy();
     if ($warstatus->getId() == 0) {
         throw new \Exception('Id needed to save a warstatus');
     } else {
         if ($this->getWarstatus((int) $warstatus->getId())) {
             $this->tableGateway->update($data, ['id' => (int) $warstatus->getId()]);
         } else {
             $data['id'] = $warstatus->getId();
             $this->tableGateway->insert($data);
         }
     }
 }
开发者ID:snowiow,项目名称:eternaldeztiny,代码行数:19,代码来源:WarstatusTable.php

示例13: saveForm

 public function saveForm(Form $form)
 {
     $data = array('name' => $form->name);
     $id = (int) $form->id;
     if ($id == 0) {
         $this->tableGateway->insert($data);
     } else {
         if ($this->getForm($id)) {
             $this->tableGateway->update($data, array('id' => $id));
         } else {
             throw new \Exception('Form id does not exist');
         }
     }
 }
开发者ID:elmosgot,项目名称:cool-builder,代码行数:14,代码来源:FormTable.php

示例14: saveNews

 /**
  * Saves the given news object to the db
  *
  * @param \News\Model\News $news
  *
  * @throws \Exception
  */
 public function saveNews(News $news)
 {
     $data = ['account_id' => $news->getAccountId(), 'title' => $news->getTitle(), 'content' => $news->getContent(), 'category_id' => $news->getCategoryId(), 'date_posted' => $news->getDatePosted()];
     $id = (int) $news->getId();
     if ($id == 0) {
         $this->tableGateway->insert($data);
     } else {
         if ($this->getNews($id)) {
             $this->tableGateway->update($data, ['id' => $id]);
         } else {
             throw new \Exception('News id does not exist');
         }
     }
 }
开发者ID:snowiow,项目名称:eternaldeztiny,代码行数:21,代码来源:NewsTable.php

示例15: saveMedia

 /**
  * Saves the given media object to the db
  *
  * @param \Media\Model\Media $media
  *
  * @throws \Exception
  */
 public function saveMedia(Media $media)
 {
     $data = ['account_id' => $media->getAccountId(), 'title' => $media->getTitle(), 'url' => $media->getUrl(), 'date_posted' => $media->getDatePosted()];
     $id = (int) $media->getId();
     if ($id == 0) {
         $this->tableGateway->insert($data);
     } else {
         if ($this->getMedia($id)) {
             $this->tableGateway->update($data, ['id' => $id]);
         } else {
             throw new \Exception('Media id does not exist');
         }
     }
 }
开发者ID:snowiow,项目名称:eternaldeztiny,代码行数:21,代码来源:MediaTable.php


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