本文整理汇总了PHP中yii\db\Query::indexBy方法的典型用法代码示例。如果您正苦于以下问题:PHP Query::indexBy方法的具体用法?PHP Query::indexBy怎么用?PHP Query::indexBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\db\Query
的用法示例。
在下文中一共展示了Query::indexBy方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getRolesByUser
public function getRolesByUser($user)
{
$query = new Query();
$query->select(['r.id', 'r.category', 'r.name', 'r.description', 'r.is_system', 'r.sort_num']);
$query->from(['r' => $this->roleTable, 'a' => $this->assignmentTable]);
$query->where('r.id=a.role');
$query->andWhere(['a.user' => $user]);
$rows = $query->indexBy('id')->all();
return $rows;
}
示例2: initLanguage
/**
* Change language through $_GET params.
*/
public function initLanguage()
{
$this->language = Yii::$app->language;
$key = static::className() . 'Languages';
$this->languages = Yii::$app->cache->get($key);
if ($this->languages === false) {
if ($this->langTable) {
$query = new Query();
$query->from($this->langTable)->where($this->langWhere)->orderBy($this->langOrder);
$this->languages = $query->indexBy('id')->all();
} else {
$this->languages = [];
}
if ($this->languages === []) {
$this->languages['0'] = ['id' => 0, $this->langColCode => $this->language, $this->langColLabel => $this->language];
}
if ($this->enableCaching) {
if ($this->langTable && $this->langColUpdatedAt) {
$query = new Query();
$sql = $query->select('COUNT(*),MAX(' . $this->langColUpdatedAt . ')')->from($this->langTable)->createCommand()->getRawSql();
Yii::$app->cache->set($key, $this->languages, $this->durationCaching, new DbDependency(['sql' => $sql]));
} else {
if ($this->durationCaching) {
Yii::$app->cache->set($key, $this->languages, $this->durationCaching);
}
}
}
}
$langKey = Yii::$app->request->get($this->langParam);
if ($this->languages) {
$language = null;
if ($langKey) {
foreach ($this->languages as $l) {
if ($l[$this->langColCode] == $langKey) {
$language = $l;
break;
}
}
if ($language === null) {
Yii::$app->on(Application::EVENT_AFTER_REQUEST, function () {
throw new HttpException(404, 'Page not exists');
});
}
}
if ($language === null) {
$language = reset($this->languages);
}
Yii::$app->language = $language[$this->langColCode];
$this->language = $language;
$this->languageId = $language['id'];
}
Yii::setAlias('weblang', Yii::getAlias('@web/' . Yii::$app->language));
}