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


PHP Table::delete方法代码示例

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


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

示例1: unlink

 /**
  * Removes all links between the passed source entity and each of the provided
  * target entities. This method assumes that all passed objects are already persisted
  * in the database and that each of them contain a primary key value.
  *
  * ### Options
  *
  * Additionally to the default options accepted by `Table::delete()`, the following
  * keys are supported:
  *
  * - cleanProperty: Whether or not to remove all the objects in `$targetEntities` that
  * are stored in `$sourceEntity` (default: true)
  *
  * By default this method will unset each of the entity objects stored inside the
  * source entity.
  *
  * ### Example:
  *
  * ```
  * $article->tags = [$tag1, $tag2, $tag3, $tag4];
  * $tags = [$tag1, $tag2, $tag3];
  * $articles->association('tags')->unlink($article, $tags);
  * ```
  *
  * `$article->get('tags')` will contain only `[$tag4]` after deleting in the database
  *
  * @param \Cake\Datasource\EntityInterface $sourceEntity an entity persisted in the source table for
  * this association
  * @param array $targetEntities list of entities persisted in the target table for
  * this association
  * @param array|bool $options list of options to be passed to the internal `delete` call,
  * or a `boolean`
  * @throws \InvalidArgumentException if non persisted entities are passed or if
  * any of them is lacking a primary key value
  * @return void
  */
 public function unlink(EntityInterface $sourceEntity, array $targetEntities, $options = [])
 {
     if (is_bool($options)) {
         $options = ['cleanProperty' => $options];
     } else {
         $options += ['cleanProperty' => true];
     }
     $this->_checkPersistenceStatus($sourceEntity, $targetEntities);
     $property = $this->property();
     $this->junction()->connection()->transactional(function () use($sourceEntity, $targetEntities, $options) {
         $links = $this->_collectJointEntities($sourceEntity, $targetEntities);
         foreach ($links as $entity) {
             $this->_junctionTable->delete($entity, $options);
         }
     });
     $existing = $sourceEntity->get($property) ?: [];
     if (!$options['cleanProperty'] || empty($existing)) {
         return;
     }
     $storage = new SplObjectStorage();
     foreach ($targetEntities as $e) {
         $storage->attach($e);
     }
     foreach ($existing as $k => $e) {
         if ($storage->contains($e)) {
             unset($existing[$k]);
         }
     }
     $sourceEntity->set($property, array_values($existing));
     $sourceEntity->dirty($property, false);
 }
开发者ID:Mingyangzu,项目名称:PHP-cakephp,代码行数:67,代码来源:BelongsToMany.php

示例2: deleteCronAction

 public function deleteCronAction()
 {
     $id = $_POST['id'] ?? null;
     if ($id) {
         try {
             $cron = $this->cronsTable->get($id);
             if (($_POST['deleteLog'] ?? false) == $id && $cron->output) {
                 $logFile = $this->site['logFolder'] . '/' . $cron->output;
                 if (!unlink($logFile)) {
                     $this->flasher->error("Could not delete log file: " . $logFile);
                 }
             }
             $this->cronsTable->delete($cron);
             $this->flasher->success('Successfully deleted cron!');
         } catch (\Exception $e) {
             $this->flasher->error("Could not delete cron: " . $e->getMessage());
         }
         $this->redirect('/admin/crons');
     }
 }
开发者ID:Swader,项目名称:nofw,代码行数:20,代码来源:CronController.php

示例3: deleteUser

 /**
  * Deletes an user record
  *
  * @param mixed $userId
  * @param array $options
  * @return boolean
  */
 public function deleteUser($userId = null, $options = [])
 {
     $entity = $this->_getUserEntity($userId);
     if ($this->UserTable->delete($entity)) {
         $this->handleFlashAndRedirect('success', $options);
         return true;
     } else {
         $this->handleFlashAndRedirect('error', $options);
         return false;
     }
 }
开发者ID:tiagocapelli,项目名称:cakephp-user-tools,代码行数:18,代码来源:UserToolComponent.php

示例4: deleteUser

 /**
  * Deletes an user record
  *
  * @param mixed $userId
  * @param array $options
  * @return boolean
  */
 public function deleteUser($userId = null, $options = [])
 {
     if (is_string($userId) || is_integer($userId)) {
         $entity = $this->UserTable->newEntity([$this->UserTable->primaryKey() => $userId]);
     }
     if (is_array($userId)) {
         $entity = $this->UserTable->newEntity($userId);
     }
     if ($this->UserTable->delete($entity)) {
         $this->handleFlashAndRedirect('success', $options);
         return true;
     } else {
         $this->handleFlashAndRedirect('error', $options);
         return false;
     }
 }
开发者ID:nielin,项目名称:cakephp-user-tools,代码行数:23,代码来源:UserToolComponent.php

示例5: beforeSave

 /**
  * Implementation of the beforeSave event, handles uploading / saving and overwriting of image records.
  *
  * @param Event $event Event object.
  * @param Entity $entity Entity object.
  * @param \ArrayObject $options Options array.
  * @return void
  */
 public function beforeSave(Event $event, Entity $entity, \ArrayObject $options)
 {
     $fields = $this->config('fields');
     $alias = $this->_table->alias();
     $options['associated'] = [$this->_imagesTable->alias() => ['validate' => false]] + $options['associated'];
     $entities = [];
     foreach ($fields as $fieldName => $fieldType) {
         $uploadedImages = [];
         $field = $entity->get($fieldName);
         $field = $fieldType == 'one' ? [$field] : $field;
         foreach ($field as $image) {
             $result = array();
             if (!empty($image['tmp_name'])) {
                 $result = $this->_upload($image['name'], $image['tmp_name'], false);
             } elseif (is_string($image)) {
                 $result = $this->_upload($image, $image, true);
             }
             if (!empty($result)) {
                 $uploadedImages[] = $result + ['model' => $alias, 'field' => $fieldName];
             }
         }
         if (!empty($uploadedImages)) {
             if (!$entity->isNew() && $fieldType == 'one') {
                 $preexisting = $this->_imagesTable->find()->where(['model' => $alias, 'field' => $fieldName, 'foreign_key' => $entity->id])->bufferResults(false);
                 foreach ($preexisting as $index => $image) {
                     $this->_imagesTable->delete($image);
                 }
             }
             foreach ($uploadedImages as $image) {
                 $entities[] = $this->_imagesTable->newEntity($image);
             }
         }
         $entity->dirty($fieldName, true);
     }
     $entity->set('_images', $entities);
 }
开发者ID:karolak,项目名称:cakephp-image,代码行数:44,代码来源:ImageBehavior.php

示例6: destroy

 /**
  * Method called on the destruction of a database session.
  *
  * @param int $id ID that uniquely identifies session in database
  * @return bool True for successful delete, false otherwise.
  */
 public function destroy($id)
 {
     return (bool) $this->_table->delete(new Entity([$this->_table->primaryKey() => $id], ['markNew' => false]));
 }
开发者ID:thanghexp,项目名称:project,代码行数:10,代码来源:DatabaseSession.php

示例7: delete

 /**
  * {@inheritDoc}
  *
  * Additional options
  * - 'strict': Throw exception instead of returning false. Defaults to false.
  */
 public function delete(EntityInterface $entity, $options = [])
 {
     $options += ['strict' => false];
     $result = parent::delete($entity, $options);
     if ($result === false && $options['strict'] === true) {
         throw new InvalidArgumentException('Could not delete ' . $entity->source() . ': ' . print_r($entity->id, true));
     }
     return $result;
 }
开发者ID:dereuromark,项目名称:cakephp-shim,代码行数:15,代码来源:Table.php

示例8: destroy

 /**
  * Method called on the destruction of a database session.
  *
  * @param int $id ID that uniquely identifies session in database
  * @return bool True for successful delete, false otherwise.
  */
 public function destroy($id)
 {
     return $this->_table->delete(new Entity([$this->_table->primaryKey() => $id]));
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:10,代码来源:DatabaseSession.php


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