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


PHP Entity::get方法代码示例

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


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

示例1: __construct

 public function __construct(Table $table, Entity $entity, $field, array $settings)
 {
     $this->setRoot(TMP . 'ProfferTests');
     $this->setTable($table->alias());
     $this->setField($field);
     $this->setSeed('proffer_test');
     if (isset($settings['thumbnailSizes'])) {
         $this->setPrefixes($settings['thumbnailSizes']);
     }
     $this->setFilename($entity->get($field));
 }
开发者ID:edukondaluetg,项目名称:CakePHP3-Proffer,代码行数:11,代码来源:TestPath.php

示例2: 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

示例3: 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

示例4: _generateUniqueSlug

 /**
  * Generate unique slug by field.
  *
  * @param Entity $entity
  * @return mixed|string
  */
 protected function _generateUniqueSlug(Entity $entity)
 {
     $conditions = [];
     $slug = $entity->get($this->_config['slug'], '');
     if ($this->_config['unique']) {
         $conditions[$this->_config['slug'] . ' LIKE'] = $slug . '%';
     }
     if ($id = $entity->get('id', false)) {
         $conditions[$this->_table->primaryKey() . ' !='] = $id;
     }
     if (empty($slug)) {
         $slug = $entity->get($this->_config['field'], 'Title');
     }
     if ($this->_config['translate']) {
         $Slug = new Slug();
         $slug = $Slug->create($slug);
     }
     $duplicates = $this->_table->find()->where($conditions)->toArray();
     if (!empty($duplicates)) {
         $duplicates = $this->_extractSlug($duplicates);
         if (!in_array($slug, $duplicates)) {
             return $slug;
         }
         $index = 1;
         $startSlug = $slug;
         while ($index > 0) {
             if (!in_array($startSlug . $this->_config['separator'] . $index, $duplicates)) {
                 $slug = $startSlug . $this->_config['separator'] . $index;
                 $index = -1;
             }
             $index++;
         }
     }
     return $slug;
 }
开发者ID:Cheren,项目名称:union,代码行数:41,代码来源:SlugBehavior.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: toggle

 /**
  * Render ajax toggle element.
  *
  * @param array|string $url
  * @param array $data
  * @param Entity|\Cake\ORM\Entity $entity
  * @return string
  */
 public function toggle($entity, $url = [], array $data = [])
 {
     if (empty($url)) {
         $url = ['action' => 'toggle', 'prefix' => $this->request->param('prefix'), 'plugin' => $this->request->param('plugin'), 'controller' => $this->request->param('controller'), (int) $entity->get('id'), (int) $entity->get('status')];
     }
     $data = Hash::merge(['url' => $url, 'entity' => $entity], $data);
     return $this->_View->element(__FUNCTION__, $data);
 }
开发者ID:UnionCMS,项目名称:Core,代码行数:16,代码来源:UnionHelper.php

示例7: basepath

 /**
  * Returns the basepath for the current field/data combination.
  * If a `path` is specified in settings, then that will be used as
  * the replacement pattern
  *
  * @return string
  * @throws LogicException if a replacement is not valid for the current dataset
  */
 public function basepath()
 {
     $defaultPath = 'webroot{DS}files{DS}{model}{DS}{field}{DS}';
     $path = Hash::get($this->settings, 'path', $defaultPath);
     if (strpos($path, '{primaryKey}') !== false) {
         if ($this->entity->isNew()) {
             throw new LogicException('{primaryKey} substitution not allowed for new entities');
         }
         if (is_array($this->table->primaryKey())) {
             throw new LogicException('{primaryKey} substitution not valid for composite primary keys');
         }
     }
     $replacements = ['{primaryKey}' => $this->entity->get($this->table->primaryKey()), '{model}' => $this->table->alias(), '{relatedModel}' => $this->entity->model, '{table}' => $this->table->table(), '{field}' => $this->field, '{time}' => time(), '{microtime}' => microtime(), '{DS}' => DIRECTORY_SEPARATOR];
     return str_replace(array_keys($replacements), array_values($replacements), $path);
 }
开发者ID:gintonicweb,项目名称:images,代码行数:23,代码来源:PolymorphicProcessor.php

示例8: __construct

 /**
  * Construct the class and setup the defaults
  *
  * @param Table $table Instance of the table
  * @param Entity $entity Instance of the entity data
  * @param string $field The name of the upload field
  * @param array $settings Array of settings for the upload field
  */
 public function __construct(Table $table, Entity $entity, $field, array $settings)
 {
     if (isset($settings['root'])) {
         $this->setRoot($settings['root']);
     } else {
         $this->setRoot(WWW_ROOT . 'files');
     }
     $this->setTable($table->alias());
     $this->setField($field);
     $this->setSeed($this->generateSeed($entity->get($settings['dir'])));
     if (isset($settings['thumbnailSizes'])) {
         $this->setPrefixes($settings['thumbnailSizes']);
     }
     $this->setFilename($entity->get($field));
 }
开发者ID:edukondaluetg,项目名称:CakePHP3-Proffer,代码行数:23,代码来源:ProfferPath.php

示例9: save

 /**
  * Takes an entity from the source table and looks if there is a field
  * matching the property name for this association. The found entity will be
  * saved on the target table for this association by passing supplied
  * `$options`
  *
  * @param \Cake\ORM\Entity $entity an entity from the source table
  * @param array|\ArrayObject $options options to be passed to the save method in
  * the target table
  * @return bool|Entity false if $entity could not be saved, otherwise it returns
  * the saved entity
  * @see Table::save()
  * @throws \InvalidArgumentException when the association data cannot be traversed.
  */
 public function save(Entity $entity, array $options = [])
 {
     $targetEntities = $entity->get($this->property());
     if (empty($targetEntities)) {
         return $entity;
     }
     if (!is_array($targetEntities) && !$targetEntities instanceof \Traversable) {
         $name = $this->property();
         $message = sprintf('Could not save %s, it cannot be traversed', $name);
         throw new \InvalidArgumentException($message);
     }
     $properties = array_combine((array) $this->foreignKey(), $entity->extract((array) $this->source()->primaryKey()));
     $target = $this->target();
     $original = $targetEntities;
     foreach ($targetEntities as $k => $targetEntity) {
         if (!$targetEntity instanceof Entity) {
             break;
         }
         if (!empty($options['atomic'])) {
             $targetEntity = clone $targetEntity;
         }
         $targetEntity->set($properties, ['guard' => false]);
         if ($target->save($targetEntity, $options)) {
             $targetEntities[$k] = $targetEntity;
             continue;
         }
         if (!empty($options['atomic'])) {
             $original[$k]->errors($targetEntity->errors());
             $entity->set($this->property(), $original);
             return false;
         }
     }
     $entity->set($this->property(), $targetEntities);
     return $entity;
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:49,代码来源:HasMany.php

示例10: beforeSave

 /**
  * Run before a model is saved, used to set up slug for model.
  *
  * @param \Cake\Event\Event $event The event that was triggered
  * @param \Cake\ORM\Entity $entity The entity being saved
  * @param array $options Array of options for the save operation
  * @return bool True if save should proceed, false otherwise
  * @throws \Cake\Error\FatalErrorException When some of the specified columns
  *  in config's "label" is not present in the entity being saved
  */
 public function beforeSave(Event $event, $entity, $options = [])
 {
     if (!$this->_enabled) {
         return true;
     }
     $config = $this->config();
     $isNew = $entity->isNew();
     if ($isNew && in_array($config['on'], ['create', 'both']) || !$isNew && in_array($config['on'], ['update', 'both'])) {
         if (!is_array($config['label'])) {
             $config['label'] = [$config['label']];
         }
         foreach ($config['label'] as $field) {
             if (!$entity->has($field)) {
                 throw new FatalErrorException(__d('cms', 'SluggableBehavior was not able to generate a slug reason: entity\'s property "{0}" not found', $field));
             }
         }
         $label = '';
         foreach ($config['label'] as $field) {
             $val = $entity->get($field);
             $label .= !empty($val) ? " {$val}" : '';
         }
         if (!empty($label)) {
             $slug = $this->_slug($label, $entity);
             $entity->set($config['slug'], $slug);
         }
     }
     return true;
 }
开发者ID:quickapps-plugins,项目名称:cms,代码行数:38,代码来源:SluggableBehavior.php

示例11: one

 /**
  * Validates a single entity by getting the correct validator object from
  * the table and traverses associations passed in $options to validate them
  * as well.
  *
  * @param \Cake\ORM\Entity $entity The entity to be validated
  * @param array|\ArrayObject $options options for validation, including an optional key of
  * associations to also be validated.
  * @return bool true if all validations passed, false otherwise
  */
 public function one(Entity $entity, $options = [])
 {
     $valid = true;
     $types = [Association::ONE_TO_ONE, Association::MANY_TO_ONE];
     $propertyMap = $this->_buildPropertyMap($options);
     $options = new ArrayObject($options);
     foreach ($propertyMap as $key => $assoc) {
         $value = $entity->get($key);
         $association = $assoc['association'];
         if (!$value) {
             continue;
         }
         $isOne = in_array($association->type(), $types);
         if ($isOne && !$value instanceof Entity) {
             $valid = false;
             continue;
         }
         $validator = $association->target()->entityValidator();
         if ($isOne) {
             $valid = $validator->one($value, $assoc['options']) && $valid;
         } else {
             $valid = $validator->many($value, $assoc['options']) && $valid;
         }
     }
     if (!isset($options['validate'])) {
         $options['validate'] = true;
     }
     return $this->_processValidation($entity, $options) && $valid;
 }
开发者ID:maitrepylos,项目名称:nazeweb,代码行数:39,代码来源:EntityValidator.php

示例12: beforeSave

 /**
  * Check if there is some files to upload and modify the entity before
  * it is saved.
  *
  * At the end, for each files to upload, unset their "virtual" property.
  *
  * @param Event  $event  The beforeSave event that was fired.
  * @param Entity $entity The entity that is going to be saved.
  *
  * @throws \LogicException When the path configuration is not set.
  * @throws \ErrorException When the function to get the upload path failed.
  *
  * @return void
  */
 public function beforeSave(Event $event, Entity $entity)
 {
     $config = $this->_config;
     foreach ($config['fields'] as $field => $fieldOption) {
         $data = $entity->toArray();
         $virtualField = $field . $config['suffix'];
         if (!isset($data[$virtualField]) || !is_array($data[$virtualField])) {
             continue;
         }
         $file = $entity->get($virtualField);
         if ((int) $file['error'] === UPLOAD_ERR_NO_FILE) {
             continue;
         }
         if (!isset($fieldOption['path'])) {
             throw new \LogicException(__('The path for the {0} field is required.', $field));
         }
         if (isset($fieldOption['prefix']) && (is_bool($fieldOption['prefix']) || is_string($fieldOption['prefix']))) {
             $this->_prefix = $fieldOption['prefix'];
         }
         $extension = (new File($file['name'], false))->ext();
         $uploadPath = $this->_getUploadPath($entity, $fieldOption['path'], $extension);
         if (!$uploadPath) {
             throw new \ErrorException(__('Error to get the uploadPath.'));
         }
         $folder = new Folder($this->_config['root']);
         $folder->create($this->_config['root'] . dirname($uploadPath));
         if ($this->_moveFile($entity, $file['tmp_name'], $uploadPath, $field, $fieldOption)) {
             if (!$this->_prefix) {
                 $this->_prefix = '';
             }
             $entity->set($field, $this->_prefix . $uploadPath);
         }
         $entity->unsetProperty($virtualField);
     }
 }
开发者ID:surjit,项目名称:Cake3-Upload,代码行数:49,代码来源:UploadBehavior.php

示例13: getFilePath

 public function getFilePath(Entity $entity, $path, $extension)
 {
     $id = $entity->get('id');
     $path = trim($path, '/');
     $replace = ['%id1000' => ceil($id / 1000), '%id100' => ceil($id / 100), '%id' => $id, '%y' => date('y'), '%m' => date('m')];
     $path = strtr($path, $replace) . '.' . $extension;
     return $path;
 }
开发者ID:bouksou,项目名称:uploader,代码行数:8,代码来源:UploaderBehavior.php

示例14: 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

示例15: afterSave

 public function afterSave(Event $event, Entity $entity, ArrayObject $options)
 {
     $ulPathSuffix = DS . date('Y') . DS . date('m') . DS . $this->_table->alias() . DS;
     $folder = new Folder(Configure::read('Upload.path') . $ulPathSuffix, true, 755);
     $table = TableRegistry::get('WoodyAttachments.Attachments');
     foreach ($this->_config['fields'] as $field => $options) {
         if (isset($entity->get($field)[0]['tmp_name'])) {
             foreach ($entity->get($field) as $file) {
                 $newFileName = substr(Text::uuid(), 0, 13) . '-' . $file['name'];
                 $attachment = array();
                 if (move_uploaded_file($file['tmp_name'], $folder->path . $newFileName)) {
                     $attachment['file_name'] = $newFileName;
                     $attachment['file_path'] = $ulPathSuffix;
                     $attachment['file_size'] = $file['size'];
                     $attachment['mime_type'] = $file['type'];
                     $attachment['real_name'] = $file['name'];
                     $attachment['entity'] = $this->_table->alias();
                     $attachment['entity_id'] = $entity->get('id');
                     $attachmentEntity = $table->newEntity($attachment);
                     if ($table->save($attachmentEntity)) {
                         $this->runFileOperations($attachmentEntity, $options);
                     }
                     unset($attachment);
                 }
             }
         } else {
             $file = $entity->get($field);
             $newFileName = substr(Text::uuid(), 0, 13) . '-' . $file['name'];
             if (move_uploaded_file($file['tmp_name'], $folder->path . $newFileName)) {
                 $attachment['file_name'] = $newFileName;
                 $attachment['file_path'] = $ulPathSuffix;
                 $attachment['file_size'] = $file['size'];
                 $attachment['mime_type'] = $file['type'];
                 $attachment['real_name'] = $file['name'];
                 $attachment['entity'] = $this->_table->alias();
                 $attachment['entity_id'] = $entity->get('id');
                 $attachmentEntity = $table->newEntity($attachment);
                 if ($table->save($attachmentEntity)) {
                     $this->runFileOperations($attachmentEntity, $options);
                 }
             }
         }
     }
     return true;
 }
开发者ID:grandfelix,项目名称:woodyattachments,代码行数:45,代码来源:UploadBehavior.php


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