本文整理汇总了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;
}
示例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');
}