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


PHP ORM\Table类代码示例

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


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

示例1: belongsToManyJunctionAliases

 /**
  * Get the array of junction aliases for all the BelongsToMany associations
  *
  * @param Table $table Table
  * @return array junction aliases of all the BelongsToMany associations
  */
 public function belongsToManyJunctionAliases(Table $table)
 {
     $extractor = function ($val) {
         return $val->junction()->alias();
     };
     return array_map($extractor, $table->associations()->type('BelongsToMany'));
 }
开发者ID:AmuseXperience,项目名称:api,代码行数:13,代码来源:AssociationFilter.php

示例2: aliasExtractor

 /**
  * Extract the aliases for associations
  *
  * @param \Cake\ORM\Table $table object to find associations on
  * @param string $assoc association to extract
  * @return array
  */
 public function aliasExtractor($table, $assoc)
 {
     $extractor = function ($val) {
         return $val->target()->alias();
     };
     return array_map($extractor, $table->associations()->type($assoc));
 }
开发者ID:djamesfar,项目名称:bake,代码行数:14,代码来源:BakeHelper.php

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

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

示例5: __construct

 /**
  * Constructor
  *
  * @param \Cake\ORM\Table $table Table who requested the behavior.
  * @param array $config Options.
  */
 public function __construct(Table $table, array $config = [])
 {
     parent::__construct($table, $config);
     $this->Table = $table;
     if ($this->config('created_by')) {
         $this->Table->belongsTo('CreatedBy', ['foreignKey' => $this->config('created_by'), 'className' => $this->config('userModel'), 'propertyName' => $this->config('createdByPropertyName')]);
     }
     if ($this->config('modified_by')) {
         $this->Table->belongsTo('ModifiedBy', ['foreignKey' => $this->config('modified_by'), 'className' => $this->config('userModel'), 'propertyName' => $this->config('modifiedByPropertyName')]);
     }
 }
开发者ID:Tomicapo,项目名称:cakephp-utils,代码行数:17,代码来源:WhoDidItBehavior.php

示例6: _subQuery

 /**
  * Generates a SQL sub-query for replacing in ORDER BY clause.
  *
  * @param string $column Name of the column being replaced by this sub-query
  * @param string|null $bundle Consider attributes only for a specific bundle
  * @return string SQL sub-query statement
  */
 protected function _subQuery($column, $bundle = null)
 {
     $alias = $this->_table->alias();
     $pk = $this->_table->primaryKey();
     $type = $this->_toolbox->getType($column);
     $subConditions = ['EavAttribute.table_alias' => $this->_table->table(), 'EavValues.entity_id' => "{$alias}.{$pk}", 'EavAttribute.name' => $column];
     if (!empty($bundle)) {
         $subConditions['EavAttribute.bundle'] = $bundle;
     }
     $subQuery = TableRegistry::get('Eav.EavValues')->find()->contain(['EavAttribute'])->select(["EavValues.value_{$type}"])->where($subConditions)->sql();
     return str_replace([':c0', ':c1', ':c2', ':c3'], ['"' . $this->_table->table() . '"', "{$alias}.{$pk}", '"' . $column . '"', '"' . $bundle . '"'], $subQuery);
 }
开发者ID:quickapps-plugins,项目名称:eav,代码行数:19,代码来源:OrderScope.php

示例7: increment

 public function increment(Table $table, $counter, $identifier)
 {
     list($alias, $field) = $this->_counterSplit($counter);
     $key = $table->primaryKey();
     if ($table->alias() !== $alias) {
         $key = $table->{$alias}->bindingKey();
         $table = TableRegistry::get($alias);
     }
     $expression = new QueryExpression("{$field} = {$field} + " . $this->_offset);
     $conditions = [$key => $identifier] + $this->_conditions;
     return $table->updateAll($expression, $conditions);
 }
开发者ID:UseMuffin,项目名称:Hits,代码行数:12,代码来源:DefaultStrategy.php

示例8: __construct

 /**
  * Constructor
  *
  * @param \Cake\ORM\Table $table Table instance
  * @param array $config Configuration
  */
 public function __construct(Table $table, array $config = [])
 {
     $tableAlias = $table->alias();
     list($plugin) = pluginSplit($table->registryAlias(), true);
     if (isset($config['referenceName'])) {
         $tableReferenceName = $config['referenceName'];
     } else {
         $tableReferenceName = $this->_referenceName($table);
     }
     $config += ['mainTableAlias' => $tableAlias, 'translationTable' => $plugin . $tableReferenceName . 'Translations', 'hasOneAlias' => $tableAlias . 'Translation'];
     parent::__construct($table, $config);
 }
开发者ID:adayth,项目名称:cakephp-shadow-translate,代码行数:18,代码来源:ShadowTranslateBehavior.php

示例9: fieldToggle

 /**
  * Toggle field value.
  *
  * @param Table|\Cake\ORM\Table $table
  * @param string|int $id
  * @param string|int $value
  * @param string $field
  * @throw BadRequestException
  * @throw RuntimeException
  */
 public function fieldToggle($table, $id, $value, $field = self::TOGGLE_DEFAULT_FIELD)
 {
     $this->_checkIsAjax();
     $this->_checkToggleData($id, $value);
     $this->_controller->viewBuilder()->layout('ajax')->templatePath('Common');
     $entity = $table->get($id);
     $entity->{$field} = !(int) $value;
     if ($result = $table->save($entity)) {
         $this->_controller->set('record', $result);
         $this->_controller->render('toggle');
     } else {
         throw new RuntimeException(__d('union', 'Failed toggling field {0} to {1}', $field, $entity->{$field}));
     }
 }
开发者ID:UnionCMS,项目名称:Core,代码行数:24,代码来源:AppComponent.php

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

示例11: replaceLinks

 /**
  * Replaces existing association links between the source entity and the target
  * with the ones passed. This method does a smart cleanup, links that are already
  * persisted and present in `$targetEntities` will not be deleted, new links will
  * be created for the passed target entities that are not already in the database
  * and the rest will be removed.
  *
  * For example, if an article is linked to tags 'cake' and 'framework' and you pass
  * to this method an array containing the entities for tags 'cake', 'php' and 'awesome',
  * only the link for cake will be kept in database, the link for 'framework' will be
  * deleted and the links for 'php' and 'awesome' will be created.
  *
  * Existing links are not deleted and created again, they are either left untouched
  * or updated so that potential extra information stored in the joint row is not
  * lost. Updating the link row can be done by making sure the corresponding passed
  * target entity contains the joint property with its primary key and any extra
  * information to be stored.
  *
  * On success, the passed `$sourceEntity` will contain `$targetEntities` as  value
  * in the corresponding property for this association.
  *
  * This method assumes that links between both the source entity and each of the
  * target entities are unique. That is, for any given row in the source table there
  * can only be one link in the junction table pointing to any other given row in
  * the target table.
  *
  * Additional options for new links to be saved can be passed in the third argument,
  * check `Table::save()` for information on the accepted options.
  *
  * ### Example:
  *
  * ```
  * $article->tags = [$tag1, $tag2, $tag3, $tag4];
  * $articles->save($article);
  * $tags = [$tag1, $tag3];
  * $articles->association('tags')->replaceLinks($article, $tags);
  * ```
  *
  * `$article->get('tags')` will contain only `[$tag1, $tag3]` at the end
  *
  * @param \Cake\Datasource\EntityInterface $sourceEntity an entity persisted in the source table for
  * this association
  * @param array $targetEntities list of entities from the target table to be linked
  * @param array $options list of options to be passed to the internal `save`/`delete` calls
  * when persisting/updating new links, or deleting existing ones
  * @throws \InvalidArgumentException if non persisted entities are passed or if
  * any of them is lacking a primary key value
  * @return bool success
  */
 public function replaceLinks(EntityInterface $sourceEntity, array $targetEntities, array $options = [])
 {
     $bindingKey = (array) $this->bindingKey();
     $primaryValue = $sourceEntity->extract($bindingKey);
     if (count(array_filter($primaryValue, 'strlen')) !== count($bindingKey)) {
         $message = 'Could not find primary key value for source entity';
         throw new InvalidArgumentException($message);
     }
     return $this->junction()->connection()->transactional(function () use($sourceEntity, $targetEntities, $primaryValue, $options) {
         $foreignKey = (array) $this->foreignKey();
         $hasMany = $this->source()->association($this->_junctionTable->alias());
         $existing = $hasMany->find('all')->where(array_combine($foreignKey, $primaryValue));
         $associationConditions = $this->conditions();
         if ($associationConditions) {
             $existing->contain($this->target()->alias());
             $existing->andWhere($associationConditions);
         }
         $jointEntities = $this->_collectJointEntities($sourceEntity, $targetEntities);
         $inserts = $this->_diffLinks($existing, $jointEntities, $targetEntities, $options);
         if ($inserts && !$this->_saveTarget($sourceEntity, $inserts, $options)) {
             return false;
         }
         $property = $this->property();
         if (count($inserts)) {
             $inserted = array_combine(array_keys($inserts), (array) $sourceEntity->get($property));
             $targetEntities = $inserted + $targetEntities;
         }
         ksort($targetEntities);
         $sourceEntity->set($property, array_values($targetEntities));
         $sourceEntity->dirty($property, false);
         return true;
     });
 }
开发者ID:Mingyangzu,项目名称:PHP-cakephp,代码行数:82,代码来源:BelongsToMany.php

示例12: initialize

 /**
  * Initialize method
  *
  * @param array $config The configuration for the Table.
  * @return void
  */
 public function initialize(array $config)
 {
     parent::initialize($config);
     $this->table('balance');
     $this->displayField('id');
     $this->primaryKey('id');
 }
开发者ID:borisknot,项目名称:cmanage,代码行数:13,代码来源:BalanceTable.php

示例13: beforeFind

 /**
  * @param \Cake\Event\Event $event
  * @param \Cake\ORM\Query $query
  * @param \ArrayObject $options
  * @param bool $primary
  * @return void
  */
 public function beforeFind(Event $event, Query $query, ArrayObject $options, $primary)
 {
     if (!$primary && !$this->_config['recursive']) {
         return;
     }
     $field = $this->_config['field'];
     if (!$field) {
         return;
     }
     $query->find('hashed');
     $idField = $this->_primaryKey;
     if ($primary && $field === $idField) {
         $query->traverseExpressions(function ($expression) {
             if (method_exists($expression, 'getField') && ($expression->getField() === $this->_primaryKey || $expression->getField() === $this->_table->alias() . '.' . $this->_primaryKey)) {
                 $expression->setValue($this->decodeHashid($expression->getValue()));
             }
             return $expression;
         });
     }
     if (!$this->_config['recursive']) {
         return;
     }
     foreach ($this->_table->associations() as $association) {
         if ($association->target()->hasBehavior('Hashid') && $association->finder() === 'all') {
             $association->finder('hashed');
         }
     }
 }
开发者ID:dereuromark,项目名称:cakephp-hashid,代码行数:35,代码来源:HashidBehavior.php

示例14: testUnaryExpression

 /**
  * test WHERE conditions against unary expression.
  *
  * @return void
  */
 public function testUnaryExpression()
 {
     $this->table->addColumn('user-birth-date', ['type' => 'date'], false);
     $first = $this->table->get(1);
     $first->set('user-birth-date', time());
     $this->table->save($first);
     $second = $this->table->find('all', ['eav' => true])->where(['user-birth-date IS' => null])->order(['id' => 'ASC'])->first();
     $this->assertTrue(!empty($second) && $second->get('id') == 2);
 }
开发者ID:quickapps-plugins,项目名称:eav,代码行数:14,代码来源:EavBehaviorTest.php

示例15: testSendNewPasswordEmail

 /**
  * testSendNewPasswordEmail
  *
  * @return void
  */
 public function testSendNewPasswordEmail()
 {
     $user = $this->Users->get(1);
     $this->Mailer->expects($this->once())->method('to')->with('adminuser@testuser.com')->will($this->returnSelf());
     $this->Mailer->expects($this->once())->method('subject')->with('Your new password')->will($this->returnSelf());
     $this->Mailer->expects($this->once())->method('template')->with('Burzum/UserTools.Users/new_password')->will($this->returnSelf());
     $this->Mailer->expects($this->once())->method('set')->with('user', $user)->will($this->returnSelf());
     $this->Mailer->sendNewPasswordEmail($user);
 }
开发者ID:burzum,项目名称:cakephp-user-tools,代码行数:14,代码来源:UsersMailerTest.php


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