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


PHP Entity::set方法代码示例

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


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

 /**
  * {@inheritDoc}
  */
 public function beforeSave(Event $event, Entity $entity, ArrayObject $options)
 {
     if (empty($options['loggedInUser'])) {
         return;
     }
     if ($entity->isNew()) {
         $entity->set('created_by', $options['loggedInUser']);
     }
     $entity->set('modified_by', $options['loggedInUser']);
 }
开发者ID:steinkel,项目名称:blame,代码行数:13,代码来源:BlameBehavior.php

示例3: beforeSave

 /**
  * save
  */
 public function beforeSave(Event $event, Entity $entity)
 {
     $config = $this->config();
     $fields = $config['fields'];
     foreach ($fields as $key => $value) {
         $historic[$value] = $entity->get($value);
     }
     if (!$entity->isNew() && ($historicOld = $this->_table->Historics->find()->where([$this->foreignKey => $entity->id])->toArray())) {
         $this->_table->Historics->patchEntity($historicOld[0], ['is_active' => 0]);
         $entity->set('historics', [$this->_table->Historics->newEntity($historic), $historicOld[0]]);
     } else {
         $entity->set('historics', [$this->_table->Historics->newEntity($historic)]);
     }
     $entity->dirty('historics', true);
 }
开发者ID:oxenti,项目名称:historic,代码行数:18,代码来源:HistoricBehavior.php

示例4: beforeSave

 /**
  * Modifies the entity before it is saved so that uploaded file data is persisted
  * in the database too.
  *
  * @param \Cake\Event\Event $event The beforeSave event that was fired
  * @param \Cake\ORM\Entity $entity The entity that is going to be saved
  * @param \ArrayObject $options the options passed to the save method
  * @return void|false
  */
 public function beforeSave(Event $event, Entity $entity, ArrayObject $options)
 {
     foreach ($this->config() as $field => $settings) {
         if (Hash::get((array) $entity->get($field), 'error') !== UPLOAD_ERR_OK) {
             if (Hash::get($settings, 'restoreValueOnFailure', true)) {
                 $entity->set($field, $entity->getOriginal($field));
                 $entity->dirty($field, false);
             }
             continue;
         }
         $data = $entity->get($field);
         $path = $this->getPathProcessor($entity, $data, $field, $settings);
         $basepath = $path->basepath();
         $filename = $path->filename();
         $data['name'] = $filename;
         $files = $this->constructFiles($entity, $data, $field, $settings, $basepath);
         $writer = $this->getWriter($entity, $data, $field, $settings);
         $success = $writer->write($files);
         if ((new Collection($success))->contains(false)) {
             return false;
         }
         $entity->set($field, $filename);
         $entity->set(Hash::get($settings, 'fields.dir', 'dir'), $basepath);
         $entity->set(Hash::get($settings, 'fields.size', 'size'), $data['size']);
         $entity->set(Hash::get($settings, 'fields.type', 'type'), $data['type']);
     }
 }
开发者ID:josegonzalez,项目名称:cakephp-upload,代码行数:36,代码来源:UploadBehavior.php

示例5: slug

 public function slug(Entity $entity)
 {
     $config = $this->config();
     if (!($value = $entity->get($config['slug']))) {
         $value = $entity->get($config['field']);
     }
     $entity->set($config['slug'], Inflector::slug($value, $config['replacement']));
 }
开发者ID:esaul314,项目名称:norn-cms,代码行数:8,代码来源:SluggableBehavior.php

示例6: beforeSave

 public function beforeSave(Event $event, Entity $entity)
 {
     $config = $this->config();
     $value = $entity->get($config['field']);
     $id = isset($entity->id) ? $entity->id : 0;
     $slug = $this->createSLug(strtolower(Inflector::slug($value, $config['replacement'])), 0, $id);
     $entity->set($config['slug'], $slug);
 }
开发者ID:Jurrieb,项目名称:lifespark,代码行数:8,代码来源:SluggableBehavior.php

示例7: beforeSave

 /**
  * beforeSave event
  *
  * @param \Cake\Event\Event $event Event.
  * @param \Cake\ORM\Entity $entity Entity.
  * @param array $options Options.
  * @return void
  */
 public function beforeSave($event, $entity, $options)
 {
     $entity->set('cakeadmin', true);
     $newPassword = $entity->get('new_password');
     if (!empty($newPassword)) {
         $entity->set('password', $entity->new_password);
         // set for password-changes
     }
 }
开发者ID:Adnan0703,项目名称:cakephp-cakeadmin,代码行数:17,代码来源:AdministratorsTable.php

示例8: beforeSave

 /**
  * Every save event triggers a new personal_key. If the entity is new then
  * check the config if there needs to be an email verification.
  */
 public function beforeSave(Event $event, Entity $entity)
 {
     $entity->set('personal_key');
     if ($entity->isNew()) {
         if (Configure::read('Users.send_email_verification')) {
             $entity->emailVerification();
         }
     }
 }
开发者ID:propellerstudios,项目名称:users-plugin,代码行数:13,代码来源:UsersTable.php

示例9: transformState

 public function transformState(Entity $entity)
 {
     $states = $this->getStates();
     $field = $this->config('field');
     $state = $this->config('defaultState');
     if (array_key_exists($entity->{$field}, $states)) {
         $state = $entity->{$field};
     }
     $state = $states[$state];
     $entity->set($this->config('field'), $state);
 }
开发者ID:mindforce,项目名称:cakephp-platform,代码行数:11,代码来源:StateableBehavior.php

示例10: beforeSave

 public function beforeSave(Event $event, Entity $entity)
 {
     // create short link if one does not yet exist
     if (empty($entity->id)) {
         $link = $this->makeShortLink();
         $Jobs = TableRegistry::get('Jobs');
         while ($Jobs->find('all')->where(['short_link' => $link])->count() > 0) {
             $link = $this->makeShortLink();
         }
         $entity->set('short_link', $link);
     }
 }
开发者ID:dlowetz,项目名称:asset-preview,代码行数:12,代码来源:JobsTable.php

示例11: afterSave

 /**
  * Before Saving the entity, slug it.
  * @param Event $event
  * @param Entity $entity
  * @return void
  */
 public function afterSave(Event $event, Entity $entity, $options)
 {
     $config = $this->config();
     # load the config built by the instantiated behavior
     $original = $entity->get($config['field']);
     # manually store $original - wasn't working for some reason otherwise
     $entity->set($config['field'], $this->_generateSlug($entity));
     # set the slug
     # if the slug is actually different than before - save it
     if ($entity->dirty() && $original != $entity->get($config['field'])) {
         $this->_table->save($entity);
     }
 }
开发者ID:cwbit,项目名称:cakephp-sluggable,代码行数:19,代码来源:SluggableBehavior.php

示例12: beforeSave

 /**
  * Before save
  * Transforma o valor de BRL para o formato SQL antes de  salvar a entidade
  * no banco de dados
  *
  * @param Event $event Instância do evento
  * @param Entity $entity Instância da entidade a ser salva pelo ORM
  * @return bool
  * @access public
  */
 public function beforeSave(Event $event, Entity $entity)
 {
     foreach ($this->_table->schema()->columns() as $campo) {
         $valor = $entity->get($campo);
         if (!empty($valor) && $this->_table->schema()->columnType($campo) === "float") {
             if (!is_string($valor) || preg_match('/^[0-9]+(\\.[0-9]+)?$/', $valor)) {
                 continue;
             }
             $entity->set($campo, str_replace(['.', ','], ['', '.'], $valor));
         }
     }
     return true;
 }
开发者ID:matheusviegas,项目名称:cake_ptbr,代码行数:23,代码来源:AjusteFloatBehavior.php

示例13: beforeSave

 /**
  * Save also related model data
  *
  * @param \Cake\Event\Event
  * @param \Cake\ORM\Entity;
  * @return void
  */
 public function beforeSave(Event $event, Entity $entity)
 {
     foreach ($this->config('fields') as $field => $mapped) {
         list($mappedTable, $mappedField) = explode('.', $mapped);
         if (!isset($this->_table->{$mappedTable}) || $this->_table->{$mappedTable}->isOwningSide($this->_table)) {
             throw new Exception(sprintf('Incorrect definition of related data to persist for %s', $mapped));
         }
         // get related entity
         $related = $this->_table->{$mappedTable}->get($entity->get($this->_table->{$mappedTable}->foreignKey()));
         // set field value
         $entity->set($field, $related->get($mappedField));
     }
 }
开发者ID:adayth,项目名称:persist-related-data,代码行数:20,代码来源:PersistRelatedDataBehavior.php

示例14: beforeSave

 /**
  * beforeSave method
  *
  * @param Event $event The event
  * @param Entity $entity The entity
  * @param ArrayObject $options Array of options
  * @param ProfferPathInterface $path Inject an instance of ProfferPath
  * @return true
  * @throws Exception
  */
 public function beforeSave(Event $event, Entity $entity, ArrayObject $options, ProfferPathInterface $path = null)
 {
     foreach ($this->config() as $field => $settings) {
         if ($entity->has($field) && is_array($entity->get($field)) && $entity->get($field)['error'] === UPLOAD_ERR_OK) {
             // Allow path to be injected or set in config
             if (!empty($settings['pathClass'])) {
                 $path = new $settings['pathClass']($this->_table, $entity, $field, $settings);
             } elseif (!isset($path)) {
                 $path = new ProfferPath($this->_table, $entity, $field, $settings);
             }
             $event = new Event('Proffer.afterPath', $entity, ['path' => $path]);
             $this->_table->eventManager()->dispatch($event);
             if (!empty($event->result)) {
                 $path = $event->result;
             }
             $path->createPathFolder();
             if ($this->moveUploadedFile($entity->get($field)['tmp_name'], $path->fullPath())) {
                 $entity->set($field, $path->getFilename());
                 $entity->set($settings['dir'], $path->getSeed());
                 // Only generate thumbnails for image uploads
                 if (getimagesize($path->fullPath()) !== false && isset($settings['thumbnailSizes'])) {
                     // Allow the transformation class to be injected
                     if (!empty($settings['transformClass'])) {
                         $imageTransform = new $settings['transformClass']($this->_table, $path);
                     } else {
                         $imageTransform = new ImageTransform($this->_table, $path);
                     }
                     $imageTransform->processThumbnails($settings);
                 }
             } else {
                 throw new Exception('Cannot upload file');
             }
         }
         unset($path);
     }
     return true;
 }
开发者ID:rohanpande,项目名称:CakePHP3-Proffer,代码行数:47,代码来源:ProfferBehavior.php

示例15: matchUser

 public function matchUser(Entity $entity)
 {
     if (!empty($entity->user_id)) {
         return true;
     }
     $netId = $entity->net_id;
     if (empty($netId)) {
         return false;
     }
     $userId = TableRegistry::get('Users')->findOrCreateByNetId($netId);
     if (empty($userId)) {
         return false;
     }
     $entity->set('user_id', $userId);
     return true;
 }
开发者ID:byu-oit-appdev,项目名称:eam,代码行数:16,代码来源:MatchUserBehavior.php


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