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


PHP Query::union方法代碼示例

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


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

示例1: _prepareQuery

 protected function _prepareQuery()
 {
     if (!$this->_query_string) {
         throw new \Exception("Error query string cannot be empty");
     }
     $q = $this->_query_string;
     $queryArticle = new Query();
     $queryArticle->select('name, preview_text, seourl, image')->from('article')->where(['like', 'name', $q])->orWhere(['like', 'preview_text', $q])->orWhere(['like', 'detail_text', $q])->orWhere(['like', 'soc_text', $q])->orWhere(['like', 'title', $q])->limit(10);
     $queryStructure = new Query();
     $queryStructure->select('label AS name, description AS preview_text, seourl, image')->from('structure')->where(['is_dir' => 0])->andWhere(['or', ['like', 'label', $q], ['like', 'content', $q], ['like', 'info', $q], ['like', 'title', $q]])->limit(10);
     $queryArticle->union($queryStructure);
     return $queryArticle;
 }
開發者ID:kashirin,項目名稱:kscms,代碼行數:13,代碼來源:SearchModel.php

示例2: loadMessagesFromDb

 /**
  * Loads the messages from database.
  * You may override this method to customize the message storage in the database.
  * @param string $category the message category.
  * @param string $language the target language.
  * @return array the messages loaded from database.
  */
 protected function loadMessagesFromDb($category, $language)
 {
     $mainQuery = new Query();
     $mainQuery->select(['t1.message message', 't2.translation translation'])->from(["{$this->sourceMessageTable} t1", "{$this->messageTable} t2"])->where('t1.id = t2.id AND t1.category = :category AND t2.language = :language')->params([':category' => $category, ':language' => $language]);
     $fallbackLanguage = substr($language, 0, 2);
     if ($fallbackLanguage != $language) {
         $fallbackQuery = new Query();
         $fallbackQuery->select(['t1.message message', 't2.translation translation'])->from(["{$this->sourceMessageTable} t1", "{$this->messageTable} t2"])->where('t1.id = t2.id AND t1.category = :category AND t2.language = :fallbackLanguage')->andWhere("t2.id NOT IN (SELECT id FROM {$this->messageTable} WHERE language = :language)")->params([':category' => $category, ':language' => $language, ':fallbackLanguage' => $fallbackLanguage]);
         $mainQuery->union($fallbackQuery, true);
     }
     $messages = $mainQuery->createCommand($this->db)->queryAll();
     return ArrayHelper::map($messages, 'message', 'translation');
 }
開發者ID:pathman,項目名稱:yii2comm,代碼行數:20,代碼來源:DbMessageSource.php


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