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


PHP Query::first方法代码示例

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


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

示例1: prepareTableData

 /**
  * converts a query Object into a flat table
  * properties are filed in first row
  *
  * @param Query $query
  * @return array
  */
 public function prepareTableData(Query $query = null)
 {
     /* first row contains properties */
     $data = [array_keys($query->first()->toArray())];
     /** add data of an entity a row */
     foreach ($query as $entity) {
         $data[] = array_values($entity->toArray());
     }
     return $data;
 }
开发者ID:psydack,项目名称:excel,代码行数:17,代码来源:ExcelHelper.php

示例2: testFirstMapReduce

 /**
  * Tests that first can be called against a query with a mapReduce
  *
  * @return void
  */
 public function testFirstMapReduce()
 {
     $map = function ($row, $key, $mapReduce) {
         $mapReduce->emitIntermediate($row['id'], 'id');
     };
     $reduce = function ($values, $key, $mapReduce) {
         $mapReduce->emit(array_sum($values));
     };
     $table = TableRegistry::get('articles', ['table' => 'articles']);
     $query = new Query($this->connection, $table);
     $query->select(['id'])->hydrate(false)->mapReduce($map, $reduce);
     $first = $query->first();
     $this->assertEquals(1, $first);
 }
开发者ID:neilan35,项目名称:betterwindow1,代码行数:19,代码来源:QueryTest.php

示例3: findHashed

 /**
  * Custom finder for hashids field.
  *
  * Options:
  * - hid (required), best to use HashidBehavior::HID constant
  * - noFirst (optional, to leave the query open for adjustments, no first() called)
  *
  * @param \Cake\ORM\Query $query Query.
  * @param array $options Array of options as described above
  * @return \Cake\ORM\Query
  */
 public function findHashed(Query $query, array $options)
 {
     $field = $this->_config['field'];
     if (!$field) {
         return $query;
     }
     $idField = $this->_primaryKey;
     $query->formatResults(function ($results) use($field, $idField) {
         $newResult = [];
         $results->each(function ($row, $key) use($field, $idField, &$newResult) {
             if (!empty($row[$idField])) {
                 $row[$field] = $this->encodeId($row[$idField]);
                 if ($row instanceof Entity) {
                     $row->dirty($field, false);
                 }
                 $newResult[] = $row;
             } elseif (is_string($row)) {
                 $newResult[$this->encodeId($key)] = $row;
             }
         });
         return new Collection($newResult);
     });
     if (!empty($options[static::HID])) {
         $id = $this->decodeHashid($options[static::HID]);
         $query->where([$idField => $id]);
     }
     $first = $this->_config['findFirst'] === true ? 'first' : $this->_config['findFirst'];
     if (!$first || !empty($options['noFirst'])) {
         return $query;
     }
     return $query->first();
 }
开发者ID:dereuromark,项目名称:cakephp-hashid,代码行数:43,代码来源:HashidBehavior.php


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