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


PHP Query::select方法代码示例

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


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

示例1: findWithCount

 public function findWithCount(Query $query, array $options)
 {
     $query->select(['count' => $query->func()->count('Users.id')]);
     $query->matching('Users');
     $query->group(['UserRoles.id']);
     return $query;
 }
开发者ID:JulienPapini,项目名称:CakeUser,代码行数:7,代码来源:UserRolesTable.php

示例2: findDistance

 /**
  * Custom finder for distance.
  *
  * Options:
  * - lat (required)
  * - lng (required)
  * - tableName
  * - distance
  *
  * @param \Cake\ORM\Query $query Query.
  * @param array $options Array of options as described above
  * @return \Cake\ORM\Query
  */
 public function findDistance(Query $query, array $options)
 {
     $options += ['tableName' => null];
     $sql = $this->distance($options['lat'], $options['lng'], null, null, $options['tableName']);
     $query->select(['distance' => $query->newExpr($sql)]);
     if (isset($options['distance'])) {
         // Some SQL versions cannot reuse the select() distance field, so we better reuse the $sql snippet
         $query->where(['(' . $sql . ') <' => $options['distance']]);
     }
     return $query->order(['distance' => 'ASC']);
 }
开发者ID:edukondaluetg,项目名称:cakephp-geo,代码行数:24,代码来源:GeocoderBehavior.php

示例3: findAuth

 /**
  * Custom finder
  *
  * @param \Cake\ORM\Query $query The query to find with
  * @param array $options The options to find with
  * @return \Cake\ORM\Query The query builder
  */
 public function findAuth(Query $query, array $options)
 {
     $query->select(['id', 'username', 'password']);
     if (!empty($options['return_created'])) {
         $query->select(['created']);
     }
     return $query;
 }
开发者ID:rashmi,项目名称:newrepo,代码行数:15,代码来源:AuthUsersTable.php

示例4: _addFilteringJoin

 /**
  * Appends any conditions required to load the relevant set of records in the
  * target table query given a filter key and some filtering values when the
  * filtering needs to be done using a subquery.
  *
  * @param \Cake\ORM\Query $query Target table's query
  * @param string $key the fields that should be used for filtering
  * @param \Cake\ORM\Query $subquery The Subquery to use for filtering
  * @return \Cake\ORM\Query
  */
 public function _addFilteringJoin($query, $key, $subquery)
 {
     $filter = [];
     $aliasedTable = $this->source()->alias();
     foreach ($subquery->clause('select') as $aliasedField => $field) {
         $filter[] = new IdentifierExpression($field);
     }
     $subquery->select($filter, true);
     if (is_array($key)) {
         $conditions = $this->_createTupleCondition($query, $key, $filter, '=');
     } else {
         $filter = current($filter);
     }
     $conditions = isset($conditions) ? $conditions : $query->newExpr([$key => $filter]);
     return $query->innerJoin([$aliasedTable => $subquery], $conditions);
 }
开发者ID:wepbunny,项目名称:cake2,代码行数:26,代码来源:SelectableAssociationTrait.php

示例5: findFull

 /**
  * Custom finder for select full fields.
  *
  * @param \Cake\ORM\Query $query The query finder.
  *
  * @return \Cake\ORM\Query
  */
 public function findFull(Query $query)
 {
     return $query->select(['id', 'first_name', 'last_name', 'username', 'avatar', 'slug', 'group_id', 'forum_post_count', 'forum_thread_count', 'forum_like_received', 'blog_articles_comment_count', 'blog_article_count', 'facebook', 'twitter', 'signature', 'end_subscription', 'created', 'last_login']);
 }
开发者ID:edukondaluetg,项目名称:Xeta,代码行数:11,代码来源:UsersTable.php

示例6: _addFieldsToQuery

 /**
  * Add translation fields to query
  *
  * If the query is using autofields (directly or implicitly) add the
  * main table's fields to the query first.
  *
  * Only add translations for fields that are in the main table, always
  * add the locale field though.
  *
  * @param \Cake\ORM\Query $query the query to check
  * @param array $config the config to use for adding fields
  * @return bool Whether a join to the translation table is required
  */
 protected function _addFieldsToQuery(Query $query, array $config)
 {
     $select = $query->clause('select');
     if (!$select) {
         return true;
     }
     $alias = $config['mainTableAlias'];
     $joinRequired = false;
     foreach ($this->_translationFields() as $field) {
         if (array_intersect($select, [$field, "{$alias}.{$field}"])) {
             $joinRequired = true;
             $query->select($query->aliasField($field, $config['hasOneAlias']));
         }
     }
     if ($joinRequired) {
         $query->select($query->aliasField('locale', $config['hasOneAlias']));
     }
     return $joinRequired;
 }
开发者ID:adayth,项目名称:cakephp-shadow-translate,代码行数:32,代码来源:ShadowTranslateBehavior.php

示例7: testContainToFieldsDefault

 /**
  * Tests that default fields for associations are added to the select clause when
  * none is specified
  *
  * @return void
  */
 public function testContainToFieldsDefault()
 {
     $contains = ['clients' => ['orders']];
     $query = new Query($this->connection, $this->table);
     $query->select()->contain($contains)->sql();
     $select = $query->clause('select');
     $expected = ['foo__id' => 'foo.id', 'clients__name' => 'clients.name', 'clients__id' => 'clients.id', 'clients__phone' => 'clients.phone', 'orders__id' => 'orders.id', 'orders__total' => 'orders.total', 'orders__placed' => 'orders.placed'];
     $expected = $this->_quoteArray($expected);
     $this->assertEquals($expected, $select);
     $contains['clients']['fields'] = ['name'];
     $query = new Query($this->connection, $this->table);
     $query->select('foo.id')->contain($contains)->sql();
     $select = $query->clause('select');
     $expected = ['foo__id' => 'foo.id', 'clients__name' => 'clients.name'];
     $expected = $this->_quoteArray($expected);
     $this->assertEquals($expected, $select);
     $contains['clients']['fields'] = [];
     $contains['clients']['orders']['fields'] = false;
     $query = new Query($this->connection, $this->table);
     $query->select()->contain($contains)->sql();
     $select = $query->clause('select');
     $expected = ['foo__id' => 'foo.id', 'clients__id' => 'clients.id', 'clients__name' => 'clients.name', 'clients__phone' => 'clients.phone'];
     $expected = $this->_quoteArray($expected);
     $this->assertEquals($expected, $select);
 }
开发者ID:alexunique0519,项目名称:Blog_Cakephp_association,代码行数:31,代码来源:EagerLoaderTest.php

示例8: findDistance

 /**
  * Custom finder for distance.
  *
  * Options:
  * - lat (required)
  * - lng (required)
  * - tableName
  * - distance
  * - sort
  *
  * @param \Cake\ORM\Query $query Query.
  * @param array $options Array of options as described above
  * @return \Cake\ORM\Query
  */
 public function findDistance(Query $query, array $options)
 {
     $options += ['tableName' => null, 'sort' => true];
     $sql = $this->distanceExpr($options['lat'], $options['lng'], null, null, $options['tableName']);
     if ($query->autoFields() === null) {
         $query->autoFields(true);
     }
     $query->select(['distance' => $query->newExpr($sql)]);
     if (isset($options['distance'])) {
         // Some SQL versions cannot reuse the select() distance field, so we better reuse the $sql snippet
         $query->where(function ($exp) use($sql, $options) {
             return $exp->lt($sql, $options['distance']);
         });
     }
     if ($options['sort']) {
         $sort = $options['sort'] === true ? 'ASC' : $options['sort'];
         $query->order(['distance' => $sort]);
     }
     return $query;
 }
开发者ID:dereuromark,项目名称:cakephp-geo,代码行数:34,代码来源:GeocoderBehavior.php

示例9: findAuth

 public function findAuth(Query $query, array $option)
 {
     $query->select(['id', 'email', 'password'])->where(['Users.active' => 1]);
     return $query;
 }
开发者ID:bleutn,项目名称:telemaque-admin,代码行数:5,代码来源:UsersTable.php

示例10: _appendFields

 /**
  * Helper function used to conditionally append fields to the select clause of
  * a query from the fields found in another query object.
  *
  * @param \Cake\ORM\Query $query the query that will get the fields appended to
  * @param \Cake\ORM\Query $surrogate the query having the fields to be copied from
  * @param array $options options passed to the method `attachTo`
  * @return void
  */
 protected function _appendFields($query, $surrogate, $options)
 {
     $options['fields'] = $surrogate->clause('select') ?: $options['fields'];
     $target = $this->_targetTable;
     if (empty($options['fields'])) {
         $f = isset($options['fields']) ? $options['fields'] : null;
         if ($options['includeFields'] && ($f === null || $f !== false)) {
             $options['fields'] = $target->schema()->columns();
         }
     }
     if (!empty($options['fields'])) {
         $query->select($query->aliasFields($options['fields'], $target->alias()));
     }
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:23,代码来源:Association.php

示例11: _selectActionFields

 /**
  * Method that adds SELECT clause to the Query to only include
  * action fields (as defined in the csv file).
  *
  * @param  \Cake\ORM\Query   $query Query object
  * @param  \Cake\Event\Event $event The event
  * @return void
  */
 protected function _selectActionFields(Query $query, Event $event)
 {
     if (!in_array($event->subject()->request->query('format'), [static::FORMAT_DATATABLES])) {
         return;
     }
     $fields = $this->_getActionFields($event->subject()->request);
     if (empty($fields)) {
         return;
     }
     $primaryKey = $event->subject()->{$event->subject()->name}->primaryKey();
     // always include primary key, useful for menus URLs
     if (!in_array($primaryKey, $fields)) {
         array_push($fields, $primaryKey);
     }
     $query->select($this->_databaseFields($fields, $event), true);
 }
开发者ID:QoboLtd,项目名称:cakephp-csv-migrations,代码行数:24,代码来源:IndexViewListener.php

示例12: findAverageLifeExpectancy

 public function findAverageLifeExpectancy(Query $query)
 {
     return $query->select(['average_exp' => $query->func()->avg('life_expectancy')]);
 }
开发者ID:harikt,项目名称:cakephp3-examples,代码行数:4,代码来源:CountriesTable.php

示例13: findAdmin

 /**
  * Find usado primeiramente pela autenticação
  */
 public function findAdmin(Query $query, array $options)
 {
     $query->select(['id', 'email', 'password'])->where(['active' => 1, 'role' => 1]);
     return $query;
 }
开发者ID:richellyitalo,项目名称:estudoscakephp,代码行数:8,代码来源:UsersTable.php

示例14: findOfficialLanguages

 public function findOfficialLanguages(Query $query)
 {
     return $query->select(['language'])->where(['is_official' => true])->distinct(['language'])->hydrate(false);
 }
开发者ID:AFPA-Dijon,项目名称:afpa,代码行数:4,代码来源:LanguagesTable.php

示例15: findDistance

 /**
  * Custom finder for distance.
  *
  * Used to be a virtual field in 2.x via setDistanceAsVirtualField()
  *
  * Options:
  * - lat (required)
  * - lng (required)
  * - tableName
  * - distance
  *
  * @param \Cake\ORM\Query $query Query.
  * @param array $options Array of options as described above
  * @return \Cake\ORM\Query
  */
 public function findDistance(Query $query, array $options)
 {
     $options += array('tableName' => null);
     $sql = $this->distance($options['lat'], $options['lng'], null, null, $options['tableName']);
     $query->select(['distance' => $query->newExpr($sql)]);
     if (isset($options['distance'])) {
         $query->where(['distance <' => $options['distance']]);
     }
     return $query->order(['distance' => 'ASC']);
 }
开发者ID:surjit,项目名称:cakephp-geo,代码行数:25,代码来源:GeocoderBehavior.php


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