當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Query::count方法代碼示例

本文整理匯總了PHP中Cake\ORM\Query::count方法的典型用法代碼示例。如果您正苦於以下問題:PHP Query::count方法的具體用法?PHP Query::count怎麽用?PHP Query::count使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Cake\ORM\Query的用法示例。


在下文中一共展示了Query::count方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: deletePOST

 /**
  * Login and submit a POST request to a $url that is expected to delete a given record,
  * and then verify its removal.
  *
  * @param int $user_id The user to login as.
  * @param String $url The url to send the request to.  Be sure to include a trailing /.
  * @param int $delete_id The id of the record to delete.
  * @param String $redirect_url The url to redirect to, after the deletion.
  * @param \Cake\ORM\Table $table The table to delete from.
  */
 protected function deletePOST($user_id, $url, $delete_id, $redirect_url, $table)
 {
     $this->fakeLogin($user_id);
     $this->post($url . $delete_id);
     $this->assertResponseSuccess();
     // 2xx, 3xx
     $this->assertRedirect($redirect_url);
     // Now verify that the record no longer exists
     $query = new Query(ConnectionManager::get('test'), $table);
     $query->find('all')->where(['id' => $delete_id]);
     $this->assertEquals(0, $query->count());
 }
開發者ID:bostontrader,項目名稱:duncemaster,代碼行數:22,代碼來源:DMIntegrationTestCase.php

示例2: beforeFind

 /**
  * Attaches comments to each entity on find operation.
  *
  * @param \Cake\Event\Event $event The event that was triggered
  * @param \Cake\ORM\Query $query The query object
  * @param array $options Additional options as an array
  * @param bool $primary Whether is find is a primary query or not
  * @return void
  */
 public function beforeFind(Event $event, $query, $options, $primary)
 {
     if ($this->_enabled && $query->count() > 0) {
         $pk = $this->_table->primaryKey();
         $tableAlias = Inflector::underscore($this->_table->alias());
         $query->contain(['Comments' => function ($query) {
             return $query->find('threaded')->contain(['Users'])->order($this->config('order'));
         }]);
         if ($this->config('count') || isset($options['comments_count']) && $options['comments_count'] === true) {
             $query->formatResults(function ($results) use($pk, $tableAlias) {
                 return $results->map(function ($entity) use($pk, $tableAlias) {
                     $entityId = $entity->{$pk};
                     $count = TableRegistry::get('Comment.Comments')->find()->where(['entity_id' => $entityId, 'table_alias' => $tableAlias])->count();
                     $entity->set('comments_count', $count);
                     return $entity;
                 });
             });
         }
     }
 }
開發者ID:quickapps-plugins,項目名稱:comment,代碼行數:29,代碼來源:CommentableBehavior.php

示例3: preparePaging

 /**
  * Prepare CakePHP paging
  *
  * @param Request $request DataTable request
  */
 protected function preparePaging(Request $request)
 {
     self::$countBeforePaging = $this->query->count();
     $this->query->limit($request->getLength());
     $this->query->offset($request->getStart());
 }
開發者ID:atkrad,項目名稱:data-tables,代碼行數:11,代碼來源:CakePHP.php


注:本文中的Cake\ORM\Query::count方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。