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


PHP Query::column方法代碼示例

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


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

示例1: getFollowTagIdsByUid

 public static function getFollowTagIdsByUid($uid)
 {
     //        $sql = "select tag_id from tag_follow where author_id=:author_id";
     //        $tag_ids = Yii::$app->db->createCommand($sql, [
     //            ':author_id' => $uid
     //        ])->queryColumn();
     //        return $tag_ids;
     $query = new Query();
     $query->select('tag_id')->from('tag_follow')->where(['author_id' => $uid]);
     return $query->column();
 }
開發者ID:awebc,項目名稱:web_xbf,代碼行數:11,代碼來源:Tag.php

示例2: find

 public static function find($module, $params = [], $page = 30)
 {
     $relation = ['country' => ['translations'], 'city' => ['country', 'country.translations', 'airports', 'airports.translations', 'translations'], 'direction' => ['iata', 'from', 'from.translations', 'from.country', 'from.country.translations', 'to', 'to.translations', 'to.country', 'to.country.translations'], 'airport' => ['translations', 'country', 'country.translations', 'city', 'city.translations'], 'airline' => []];
     if (!empty($params['relation'])) {
         $relation = array_merge($relation, $params['relation']);
         unset($params['relation']);
     }
     $model = 'common\\models\\Received' . ucfirst($module);
     if (!class_exists($model)) {
         throw new ErrorException('no module > ' . $module);
     }
     $query = new Query();
     $query->select(["{$module}.id"])->from([$module => "received_{$module}"]);
     if ($module == 'direction') {
         $query->addSelect(["{$module}.popularity"]);
         $query->orderBy(['direction.popularity' => SORT_DESC]);
         $query->groupBy(['direction.city_to_code', 'direction.city_from_code']);
     }
     foreach ($params as $key => $value) {
         $postfix = '';
         if ($key == 'from' || $key == 'to') {
             $postfix = "_{$key}";
             $key = 'city';
         }
         if (is_array($value) && $value) {
             $query->leftJoin([$key . $postfix => "received_{$key}"], "{$module}.{$key}{$postfix}_code = {$key}{$postfix}.code");
             foreach ($value as $_key => $_value) {
                 if (is_array($_value) && $_value) {
                     $query->leftJoin([$_key . $postfix => "received_{$_key}"], "{$key}{$postfix}.{$_key}_code = {$_key}{$postfix}.code");
                     foreach ($_value as $__key => $__value) {
                         $query->andFilterWhere(["{$_key}{$postfix}.{$__key}" => $__value]);
                     }
                 } else {
                     $query->andFilterWhere(["{$key}{$postfix}.{$_key}" => $_value]);
                 }
             }
         } else {
             $query->andFilterWhere(["{$module}.{$key}{$postfix}" => $value]);
         }
     }
     $total = $query->count();
     $id = $query->column();
     if ($page > 1) {
         if (!empty($_GET['page'])) {
             $_page = $_GET['page'];
         } else {
             $_page = 0;
         }
         $id = array_slice($id, $_page > 1 ? ($_page - 1) * $page : 0, $page);
         //            VarDumper::dump($id);
     }
     /** @var $model \yii\db\ActiveRecord */
     $query = $model::find()->where(['id' => $id])->asArray();
     if ($module == 'direction') {
         $query->orderBy(['received_direction.popularity' => SORT_DESC]);
     }
     $query->with($relation[$module]);
     if ($page == 1) {
         return $query->all();
     }
     $pagination = new Pagination(['totalCount' => $total, 'pageSize' => $page, 'pageSizeParam' => false]);
     if ($page == 1) {
         $page = 0;
     }
     $query->offset(0)->limit($page);
     return [$query->all(), $pagination];
 }
開發者ID:BeforyDeath,項目名稱:travel,代碼行數:67,代碼來源:ReceivedFilter.php

示例3: loadMessages

 private function loadMessages($className)
 {
     if (!is_subclass_of($className, \yii\db\ActiveRecord::className())) {
         throw new \Exception("'{$className}' does not extend \\yii\\db\\ActiveRecord.");
     }
     $attributeNames = $this->getTranslatableAttributes($className);
     $messages = [];
     foreach ($attributeNames as $attributeName) {
         $query = new Query();
         $query->select($attributeName)->distinct()->from($className::tableName());
         $messages = array_merge($messages, $query->column());
     }
     return $messages;
 }
開發者ID:iw-reload,項目名稱:iw,代碼行數:14,代碼來源:MessageController.php


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