當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。