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