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


PHP Table::aliasField方法代码示例

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


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

示例1: beforeFind

 /**
  * Callback method that listens to the `beforeFind` event in the bound
  * table. It modifies the passed query by eager loading the translated fields
  * and adding a formatter to copy the values into the main table records.
  *
  * @param \Cake\Event\Event $event The beforeFind event that was fired.
  * @param \Cake\ORM\Query $query Query
  * @param \ArrayObject $options The options for the query
  * @return void
  */
 public function beforeFind(Event $event, Query $query, $options)
 {
     $locale = $this->locale();
     if ($locale === $this->config('defaultLocale')) {
         return;
     }
     $conditions = function ($field, $locale, $query, $select) {
         return function ($q) use($field, $locale, $query, $select) {
             $q->where([$q->repository()->aliasField('locale') => $locale]);
             if ($query->autoFields() || in_array($field, $select, true) || in_array($this->_table->aliasField($field), $select, true)) {
                 $q->select(['id', 'content']);
             }
             return $q;
         };
     };
     $contain = [];
     $fields = $this->_config['fields'];
     $alias = $this->_table->alias();
     $select = $query->clause('select');
     $changeFilter = isset($options['filterByCurrentLocale']) && $options['filterByCurrentLocale'] !== $this->_config['onlyTranslated'];
     foreach ($fields as $field) {
         $name = $alias . '_' . $field . '_translation';
         $contain[$name]['queryBuilder'] = $conditions($field, $locale, $query, $select);
         if ($changeFilter) {
             $filter = $options['filterByCurrentLocale'] ? 'INNER' : 'LEFT';
             $contain[$name]['joinType'] = $filter;
         }
     }
     $query->contain($contain);
     $query->formatResults(function ($results) use($locale) {
         return $this->_rowMapper($results, $locale);
     }, $query::PREPEND);
 }
开发者ID:wepbunny,项目名称:cake2,代码行数:43,代码来源:TranslateBehavior.php

示例2: _getQuery

 /**
  * Builds a query for loading the passed list of entity objects along with the
  * associations specified in $contain.
  *
  * @param Cake\Collection\CollectionInterface $objects The original entitites
  * @param array $contain The associations to be loaded
  * @param Cake\ORM\Table $source The table to use for fetching the top level entities
  * @return Cake\ORM\Query
  */
 protected function _getQuery($objects, $contain, $source)
 {
     $primaryKey = $source->primaryKey();
     $method = is_string($primaryKey) ? 'get' : 'extract';
     $keys = $objects->map(function ($entity) use($primaryKey, $method) {
         return $entity->{$method}($primaryKey);
     });
     $query = $source->find()->select((array) $primaryKey)->where(function ($exp, $q) use($primaryKey, $keys, $source) {
         if (is_array($primaryKey) && count($primaryKey) === 1) {
             $primaryKey = current($primaryKey);
         }
         if (is_string($primaryKey)) {
             return $exp->in($source->aliasField($primaryKey), $keys->toList());
         }
         $types = array_intersect_key($q->defaultTypes(), array_flip($primaryKey));
         $primaryKey = array_map([$source, 'aliasField'], $primaryKey);
         return new TupleComparison($primaryKey, $keys->toList(), $types, 'IN');
     })->contain($contain);
     foreach ($query->eagerLoader()->attachableAssociations($source) as $loadable) {
         $config = $loadable->config();
         $config['includeFields'] = true;
         $loadable->config($config);
     }
     return $query;
 }
开发者ID:eddiePower,项目名称:cakephp,代码行数:34,代码来源:LazyEagerLoader.php

示例3: testAliasField

 /**
  * Test that aliasField() works.
  *
  * @return void
  */
 public function testAliasField()
 {
     $table = new Table(['alias' => 'Users']);
     $this->assertEquals('Users.id', $table->aliasField('id'));
 }
开发者ID:jdaosavanh,项目名称:clickerwebapp,代码行数:10,代码来源:TableTest.php

示例4: _process

 /**
  * Processes the records.
  *
  * @param \Cake\ORM\Table $table
  * @param int $chunkCount
  * @param int $chunkSize
  * @return void
  */
 protected function _process(Table $table, $chunkCount, $chunkSize)
 {
     $query = $table->find();
     if ($table->hasFinder('purifier')) {
         $query->find('purifier');
     }
     $fields = explode(',', $this->param('fields'));
     $fields[] = $table->primaryKey();
     $results = $query->select($fields)->offset($chunkCount)->limit($chunkSize)->orderDesc($table->aliasField($table->primaryKey()))->all();
     if (empty($results)) {
         return;
     }
     foreach ($results as $result) {
         try {
             $table->save($result);
             $chunkCount++;
         } catch (\Exception $e) {
             $this->error($e->getMessage());
         }
     }
 }
开发者ID:burzum,项目名称:cakephp-html-purifier,代码行数:29,代码来源:PurifierShell.php


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