當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。