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