當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Entity::unsetProperty方法代碼示例

本文整理匯總了PHP中Cake\ORM\Entity::unsetProperty方法的典型用法代碼示例。如果您正苦於以下問題:PHP Entity::unsetProperty方法的具體用法?PHP Entity::unsetProperty怎麽用?PHP Entity::unsetProperty使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Cake\ORM\Entity的用法示例。


在下文中一共展示了Entity::unsetProperty方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: uploadFile

 /**
  * get appropriate fields with files
  * move uploaded file and set path to entity field, but only if a file was selected
  *
  * @param Entity $entity
  */
 public function uploadFile(Entity $entity)
 {
     $config = $this->config();
     if (!is_array($config['field'])) {
         $field = $entity->get($config['field']);
         if (empty($field['tmp_name'])) {
             $entity->unsetProperty($config['field']);
         } else {
             if ($entity->get($config['field']) != $entity->getOriginal($config['field'])) {
                 $originalFilePath = $entity->getOriginal($config['field']);
                 $this->_delete($originalFilePath);
             }
             $filePath = $this->_moveFile($field);
             $entity->set($config['field'], $filePath);
         }
     } else {
         foreach ($config['field'] as $value) {
             $field = $entity->get($value);
             if (empty($field['tmp_name'])) {
                 $entity->unsetProperty($config['field']);
             } else {
                 if ($entity->get($config['field']) != $entity->getOriginal($config['field'])) {
                     $originalFilePath = $entity->getOriginal($config['field']);
                     $this->_delete($originalFilePath);
                 }
                 $filePath = $this->_moveFile($field);
                 $entity->set($config['field'], $filePath);
             }
         }
     }
 }
開發者ID:pdmshrestha,項目名稱:cakephp3-uploadBehavior,代碼行數:37,代碼來源:UploadBehavior.php

示例2: testUnsetMultiple

 /**
  * Tests unsetProperty whith multiple properties
  *
  * @return void
  */
 public function testUnsetMultiple()
 {
     $entity = new Entity(['id' => 1, 'name' => 'bar', 'thing' => 2]);
     $entity->unsetProperty(['id', 'thing']);
     $this->assertFalse($entity->has('id'));
     $this->assertTrue($entity->has('name'));
     $this->assertFalse($entity->has('thing'));
 }
開發者ID:jeremyheaton,項目名稱:ultiswap,代碼行數:13,代碼來源:EntityTest.php

示例3: afterSave

 /**
  * [afterSave description]
  * @param  Event       $event   [description]
  * @param  Entity      $entity  [description]
  * @param  ArrayObject $options [description]
  * @return void
  */
 public function afterSave(Event $event, Entity $entity, ArrayObject $options)
 {
     if (!empty($entity->_images)) {
         foreach ($entity->_images as $imageEntity) {
             $this->generatePresets($imageEntity);
         }
         $entity->unsetProperty('_images');
     }
 }
開發者ID:edukondaluetg,項目名稱:image,代碼行數:16,代碼來源:ImageBehavior.php

示例4: beforeSave

 /**
  * Hashing the password and whitelisting
  *
  * @param \Cake\Event\Event $event
  * @param \Cake\ORM\Entity $entity
  * @throws \Exception
  * @return void
  */
 public function beforeSave(Event $event, Entity $entity)
 {
     $formField = $this->_config['formField'];
     $field = $this->_config['field'];
     if ($entity->get($formField) !== null) {
         $cost = !empty($this->_config['hashCost']) ? $this->_config['hashCost'] : 10;
         $options = ['cost' => $cost];
         /** @var \Cake\Auth\AbstractPasswordHasher $PasswordHasher */
         $PasswordHasher = $this->_getPasswordHasher($this->_config['passwordHasher'], $options);
         $entity->set($field, $PasswordHasher->hash($entity->get($formField)));
         if (!$entity->get($field)) {
             throw new Exception('Empty field');
         }
         $entity->unsetProperty($formField);
         //$entity->set($formField, null);
         if ($this->_config['confirm']) {
             $formFieldRepeat = $this->_config['formFieldRepeat'];
             $entity->unsetProperty($formFieldRepeat);
             //unset($Model->data[$table->alias()][$formFieldRepeat]);
         }
         if ($this->_config['current']) {
             $formFieldCurrent = $this->_config['formFieldCurrent'];
             $entity->unsetProperty($formFieldCurrent);
             //unset($Model->data[$table->alias()][$formFieldCurrent]);
         }
     }
 }
開發者ID:alescx,項目名稱:cakephp-tools,代碼行數:35,代碼來源:PasswordableBehavior.php

示例5: afterSave

 /**
  * Unsets the temporary `_i18n` property after the entity has been saved
  *
  * @param \Cake\Event\Event $event The beforeSave event that was fired
  * @param \Cake\ORM\Entity $entity The entity that is going to be saved
  * @return void
  */
 public function afterSave(Event $event, Entity $entity)
 {
     $entity->unsetProperty('_i18n');
 }
開發者ID:neilan35,項目名稱:betterwindow1,代碼行數:11,代碼來源:TranslateBehavior.php

示例6: encodeBitmaskData

 /**
  * @param Entity $entity
  * @return void
  */
 public function encodeBitmaskData(Entity $entity)
 {
     $field = $this->_config['field'];
     if (!($mappedField = $this->_config['mappedField'])) {
         $mappedField = $field;
     }
     $default = null;
     $schema = $this->_table->schema()->column($field);
     if ($schema && isset($schema['default'])) {
         $default = $schema['default'];
     }
     if ($this->_config['defaultValue'] !== null) {
         $default = $this->_config['defaultValue'];
     }
     if ($entity->get($mappedField) !== null) {
         $entity->set($field, $this->encodeBitmask($entity->get($mappedField), $default));
     }
     if ($field !== $mappedField) {
         $entity->unsetProperty($mappedField);
     }
 }
開發者ID:olmprakash,項目名稱:cakephp-tools,代碼行數:25,代碼來源:BitmaskedBehavior.php

示例7: _ensureStatus

 /**
  * Ensures that content content has the correct publishing status based in content
  * type restrictions.
  *
  * If it's a new content it will set the correct status. However if it's an
  * existing content and user has no publishing permissions this method will not
  * change content's status, so it will remain published if it was already
  * published by an administrator.
  *
  * @param \Cake\ORM\Entity $entity The content
  * @return void
  */
 protected function _ensureStatus(Entity $entity)
 {
     if (!$entity->has('status')) {
         return;
     }
     if (!$entity->has('content_type') && ($entity->has('content_type_id') || $entity->has('content_type_slug'))) {
         if ($entity->has('content_type_id')) {
             $type = $this->ContentTypes->get($entity->get('content_type_id'));
         } else {
             $type = $this->ContentTypes->find()->where(['content_type_slug' => $entity->get('content_type_id')])->limit(1)->first();
         }
     } else {
         $type = $entity->get('content_type');
     }
     if ($type && !$type->userAllowed('publish')) {
         if ($entity->isNew()) {
             $entity->set('status', false);
         } else {
             $entity->unsetProperty('status');
         }
     }
 }
開發者ID:quickapps-plugins,項目名稱:content,代碼行數:34,代碼來源:ContentsTable.php

示例8: afterSave

 /**
  * Unsets the temporary `__version` property after the entity has been saved
  *
  * @param \Cake\Event\Event $event The beforeSave event that was fired
  * @param \Cake\ORM\Entity $entity The entity that is going to be saved
  * @return void
  */
 public function afterSave(Event $event, Entity $entity)
 {
     $property = $this->versionAssociation()->property();
     $entity->unsetProperty($property);
 }
開發者ID:josegonzalez,項目名稱:cakephp-version,代碼行數:12,代碼來源:VersionBehavior.php

示例9: beforeSave

 /**
  * Hashing the password and whitelisting
  *
  * @param Event $event
  * @return void
  */
 public function beforeSave(Event $event, Entity $entity)
 {
     $formField = $this->_config['formField'];
     $field = $this->_config['field'];
     if ($entity->get($formField) !== null) {
         $cost = !empty($this->_config['hashCost']) ? $this->_config['hashCost'] : 10;
         $options = ['cost' => $cost];
         $PasswordHasher = $this->_getPasswordHasher($this->_config['passwordHasher']);
         $entity->set($field, $PasswordHasher->hash($entity->get($formField), $options));
         if (!$entity->get($field)) {
             throw new \Exception('Empty field');
         }
         $entity->unsetProperty($formField);
         //$entity->set($formField, null);
         if ($this->_config['confirm']) {
             $formFieldRepeat = $this->_config['formFieldRepeat'];
             $entity->unsetProperty($formFieldRepeat);
             //unset($Model->data[$table->alias()][$formFieldRepeat]);
         }
         if ($this->_config['current']) {
             $formFieldCurrent = $this->_config['formFieldCurrent'];
             $entity->unsetProperty($formFieldCurrent);
             //unset($Model->data[$table->alias()][$formFieldCurrent]);
         }
     }
     // Update whitelist
     $this->_modifyWhitelist($entity, true);
     return true;
 }
開發者ID:olmprakash,項目名稱:cakephp-tools,代碼行數:35,代碼來源:PasswordableBehavior.php


注:本文中的Cake\ORM\Entity::unsetProperty方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。