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


PHP User::getDb方法代码示例

本文整理汇总了PHP中bizley\podium\models\User::getDb方法的典型用法代码示例。如果您正苦于以下问题:PHP User::getDb方法的具体用法?PHP User::getDb怎么用?PHP User::getDb使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在bizley\podium\models\User的用法示例。


在下文中一共展示了User::getDb方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: actionPromote

 /**
  * Promoting the user of given ID.
  * @param integer $id
  * @return \yii\web\Response
  */
 public function actionPromote($id = null)
 {
     if (User::can(Rbac::PERM_PROMOTE_USER)) {
         $model = User::findOne((int) $id);
         if (empty($model)) {
             $this->error(Yii::t('podium/flash', 'Sorry! We can not find User with this ID.'));
         } else {
             if ($model->role != User::ROLE_MEMBER) {
                 $this->error(Yii::t('podium/flash', 'You can only promote Members to Moderators.'));
             } else {
                 $transaction = User::getDb()->beginTransaction();
                 try {
                     if ($model->promoteTo(User::ROLE_MODERATOR)) {
                         if (Yii::$app->authManager->getRolesByUser($model->id)) {
                             Yii::$app->authManager->revoke(Yii::$app->authManager->getRole(Rbac::ROLE_USER), $model->id);
                         }
                         if (Yii::$app->authManager->assign(Yii::$app->authManager->getRole(Rbac::ROLE_MODERATOR), $model->id)) {
                             Activity::updateRole($model->id, User::ROLE_MODERATOR);
                             $transaction->commit();
                             Log::info('User promoted', $model->id, __METHOD__);
                             $this->success(Yii::t('podium/flash', 'User has been promoted.'));
                             return $this->redirect(['admin/mods', 'id' => $model->id]);
                         }
                     }
                     $this->error(Yii::t('podium/flash', 'Sorry! There was an error while promoting the user.'));
                 } catch (Exception $e) {
                     $transaction->rollBack();
                     Log::error($e->getMessage(), null, __METHOD__);
                     $this->error(Yii::t('podium/flash', 'Sorry! There was an error while promoting the user.'));
                 }
             }
         }
     } else {
         $this->error(Yii::t('podium/flash', 'You are not allowed to perform this action.'));
     }
     return $this->redirect(['members']);
 }
开发者ID:aekkapun,项目名称:yii2-podium,代码行数:42,代码来源:AdminController.php

示例2: actionPromote

 /**
  * Promoting the user of given ID.
  * @param integer $id
  * @return \yii\web\Response
  */
 public function actionPromote($id = null)
 {
     $model = (new PodiumUser())->findOne((int) $id);
     if (empty($model->user)) {
         $this->error('Sorry! We can not find User with this ID.');
     } else {
         if ($model->getRole() != User::ROLE_MEMBER) {
             $this->error('You can only promote Members to Moderators.');
         } else {
             $transaction = User::getDb()->beginTransaction();
             try {
                 if ($model->promoteTo(User::ROLE_MODERATOR)) {
                     if (!empty(Yii::$app->authManager->getRolesByUser($model->getId()))) {
                         Yii::$app->authManager->revoke(Yii::$app->authManager->getRole('podiumUser'), $model->getId());
                     }
                     if (Yii::$app->authManager->assign(Yii::$app->authManager->getRole('podiumModerator'), $model->getId())) {
                         $transaction->commit();
                         Log::info('User promoted', !empty($model->getId()) ? $model->getId() : '', __METHOD__);
                         $this->success('User has been promoted.');
                         return $this->redirect(['admin/mods', 'id' => $model->getId()]);
                     }
                 }
                 $this->error('Sorry! There was an error while promoting the user.');
             } catch (Exception $e) {
                 $transaction->rollBack();
                 Log::error($e->getMessage(), null, __METHOD__);
                 $this->error('Sorry! There was an error while promoting the user.');
             }
         }
     }
     return $this->redirect(['members']);
 }
开发者ID:keltstr,项目名称:yii2-podium,代码行数:37,代码来源:AdminController.php


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