• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP ORM\Entity类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: _prettify

 /**
  * Method that renders Entity values through Field Handler Factory.
  *
  * @param  Cake\ORM\Entity       $entity    Entity instance
  * @param  Cake\ORM\Table|string $table     Table instance
  * @param  array                 $fields    Fields to prettify
  * @return void
  */
 protected function _prettify(Entity $entity, $table, array $fields = [])
 {
     if (!$this->__fhf instanceof FieldHandlerFactory) {
         $this->__fhf = new FieldHandlerFactory();
     }
     if (empty($fields)) {
         $fields = array_keys($entity->toArray());
     }
     foreach ($fields as $field) {
         // handle belongsTo associated data
         if ($entity->{$field} instanceof Entity) {
             $tableName = $table->association($entity->{$field}->source())->className();
             $this->_prettify($entity->{$field}, $tableName);
         }
         // handle hasMany associated data
         if (is_array($entity->{$field})) {
             if (empty($entity->{$field})) {
                 continue;
             }
             foreach ($entity->{$field} as $associatedEntity) {
                 if (!$associatedEntity instanceof Entity) {
                     continue;
                 }
                 $tableName = $table->association($associatedEntity->source())->className();
                 $this->_prettify($associatedEntity, $tableName);
             }
         }
         $renderOptions = ['entity' => $entity];
         $entity->{$field} = $this->__fhf->renderValue($table instanceof Table ? $table->registryAlias() : $table, $field, $entity->{$field}, $renderOptions);
     }
 }
开发者ID:QoboLtd,项目名称:cakephp-csv-migrations,代码行数:39,代码来源:PrettifyTrait.php


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


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


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


示例5: afterSave

 /**
  * After Save Callback
  *
  * @param Cake/Event/Event $event The afterSave event that was fired.
  * @param Cake/ORM/Entity $entity The entity
  * @param ArrayObject $options Options
  * @return void
  */
 public function afterSave(Event $event, Entity $entity, ArrayObject $options)
 {
     if ($entity->isNew()) {
         $this->saveDefaultUri($entity);
     } else {
         // Change route.
         if ($entity->dirty()) {
             $SeoUris = TableRegistry::get('Seo.SeoUris');
             $SeoCanonicals = TableRegistry::get('Seo.SeoCanonicals');
             $urlsConfig = $this->config('urls');
             foreach ($urlsConfig as $key => $url) {
                 $uri = $this->_getUri($entity, $url);
                 $seoUri = $SeoUris->find()->contain(['SeoCanonicals'])->where(['model' => $this->_table->alias(), 'foreign_key' => $entity->id, 'locale' => isset($url['locale']) ? $url['locale'] : null])->first();
                 if ($seoUri) {
                     $seoUri = $SeoUris->patchEntity($seoUri, ['uri' => $uri], ['associated' => ['SeoCanonicals']]);
                     $SeoUris->save($seoUri);
                     $seoUriCanonical = Router::fullBaseUrl() . $uri;
                     $seoUri->seo_canonical->set('canonical', $seoUriCanonical);
                     $SeoCanonicals->save($seoUri->seo_canonical);
                 }
             }
         }
     }
     \Cake\Cache\Cache::clear(false, 'seo');
 }
开发者ID:orgasmicnightmare,项目名称:cakephp-seo,代码行数:33,代码来源:SeoBehavior.php


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


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


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


示例9: getAttributes

 /**
  * Get resource attributes.
  *
  * @param \Cake\ORM\Entity $resource Entity resource
  * @return array
  */
 public function getAttributes($resource)
 {
     if ($resource->has($this->idField)) {
         $hidden = array_merge($resource->hiddenProperties(), [$this->idField]);
         $resource->hiddenProperties($hidden);
     }
     return $resource->toArray();
 }
开发者ID:josbeir,项目名称:cakephp-json-api,代码行数:14,代码来源:EntitySchema.php


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


示例11: beforeSave

 public function beforeSave(Event $event, Entity $entity, ArrayObject $options)
 {
     if ($entity->isNew() && empty($entity->user_id)) {
         $entity->errors('user_id', ['not_found', 'User not found']);
         $entity->errors('net_id', ['not_found', 'User not found']);
         return false;
     }
 }
开发者ID:byu-oit-appdev,项目名称:byusa-clubs,代码行数:8,代码来源:MatchUserBehavior.php


示例12: afterSave

 /**
  * AfterSave callback.
  *
  * @param \Cake\Event\Event $event   The afterSave event that was fired.
  * @param \Cake\ORM\Entity $entity  The entity that was saved.
  * @param \ArrayObject $options The options passed to the callback.
  *
  * @return bool
  */
 public function afterSave(Event $event, Entity $entity, ArrayObject $options)
 {
     if ($entity->isNew()) {
         $comment = new Event('Model.BlogArticlesComments.add', $this, ['comment' => $entity]);
         $this->eventManager()->dispatch($comment);
     }
     return true;
 }
开发者ID:edukondaluetg,项目名称:Xeta,代码行数:17,代码来源:BlogArticlesCommentsTable.php


示例13: __construct

 /**
  * Constructor
  *
  * @param \Cake\ORM\Entity $entity Entity
  * @param int $code code to report to client
  */
 public function __construct(Entity $entity, $code = 422)
 {
     $this->_validationErrors = array_filter((array) $entity->errors());
     $flat = Hash::flatten($this->_validationErrors);
     $errorCount = $this->_validationErrorCount = count($flat);
     $this->message = __dn('crud', 'A validation error occurred', '{0} validation errors occurred', $errorCount, [$errorCount]);
     parent::__construct($this->message, $code);
 }
开发者ID:AmuseXperience,项目名称:api,代码行数:14,代码来源:ValidationException.php


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


示例15: afterSave

 /**
  * Called after an entity is saved
  * @param \Cake\Event\Event $event Event object
  * @param \Cake\ORM\Entity $entity Entity object
  * @param \ArrayObject $options Options
  * @return void
  * @uses MeCms\Model\Table\AppTable::afterSave()
  */
 public function afterSave(\Cake\Event\Event $event, \Cake\ORM\Entity $entity, \ArrayObject $options)
 {
     //Creates the folder
     if ($entity->isNew()) {
         (new Folder())->create(PHOTOS . DS . $entity->id, 0777);
     }
     parent::afterSave($event, $entity, $options);
 }
开发者ID:mirko-pagliai,项目名称:me-cms,代码行数:16,代码来源:PhotosAlbumsTable.php


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


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


示例18: testBeforeSaveEditEntity

 /**
  * test beforeSave() method when updating an existing entity.
  *
  * @return void
  */
 public function testBeforeSaveEditEntity()
 {
     $event = new Event('Model.beforeSave');
     $entity = new Entity(['id' => 100, 'title' => 'Random String Title', 'slug' => '']);
     $entity->isNew(false);
     $this->Behavior->beforeSave($event, $entity);
     $this->assertTrue(!$entity->has('created_by'));
     $this->assertEquals(1, $entity->get('modified_by'));
 }
开发者ID:quickapps-plugins,项目名称:user,代码行数:14,代码来源:WhoDidItBehaviorTest.php


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


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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP ORM\Query类代码示例发布时间:2022-05-23
下一篇:
PHP ORM\Behavior类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap