当前位置: 首页>>代码示例>>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;未经允许,请勿转载。