当前位置: 首页>>代码示例>>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;未经允许,请勿转载。