当前位置: 首页>>代码示例>>PHP>>正文


PHP Query::indexBy方法代码示例

本文整理汇总了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;
 }
开发者ID:hucongyang,项目名称:lulucms2,代码行数:10,代码来源:RbacService.php

示例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));
 }
开发者ID:pavlinter,项目名称:yii2-dot-translation,代码行数:56,代码来源:I18N.php


注:本文中的yii\db\Query::indexBy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。