本文整理汇总了PHP中bizley\podium\models\User::findOne方法的典型用法代码示例。如果您正苦于以下问题:PHP User::findOne方法的具体用法?PHP User::findOne怎么用?PHP User::findOne使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bizley\podium\models\User
的用法示例。
在下文中一共展示了User::findOne方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validateCurrentPassword
public function validateCurrentPassword($attribute)
{
if (!empty($this->user_id)) {
$user = User::findOne($this->user_id);
if (!$user->validatePassword($this->current_password)) {
$this->addError($attribute, Yii::t('podium/view', 'Current password is incorrect.'));
}
}
}
示例2: actionView
/**
* Listing the details of user of given ID.
* @param integer $id
* @return string|\yii\web\Response
*/
public function actionView($id = null)
{
$model = User::findOne((int) $id);
if (empty($model)) {
$this->error(Yii::t('podium/flash', 'Sorry! We can not find Member with this ID.'));
return $this->redirect(['admin/members']);
}
return $this->render('view', ['model' => $model]);
}
示例3: actionForum
/**
* Updating the forum details.
* @return string|\yii\web\Response
*/
public function actionForum()
{
$model = Meta::findOne(['user_id' => Yii::$app->user->id]);
if (empty($model)) {
$model = new Meta();
}
if ($model->load(Yii::$app->request->post())) {
$model->user_id = Yii::$app->user->id;
$uploadAvatar = false;
$path = Yii::getAlias('@webroot/avatars');
$avatar = UploadedFile::getInstance($model, 'image');
if ($avatar) {
$folderExists = true;
if (!file_exists($path)) {
if (!FileHelper::createDirectory($path)) {
$folderExists = false;
Log::error('Error while creating avatars folder', null, __METHOD__);
$this->error('Sorry! There was an error while creating the avatars folder. Contact administrator about this problem.');
}
}
if ($folderExists) {
if (!empty($model->avatar)) {
if (!unlink($path . DIRECTORY_SEPARATOR . $model->avatar)) {
Log::error('Error while deleting old avatar image', null, __METHOD__);
}
}
$model->avatar = Yii::$app->security->generateRandomString() . '.' . $avatar->getExtension();
$uploadAvatar = true;
}
}
if ($model->save()) {
if ($uploadAvatar) {
if (!$avatar->saveAs($path . DIRECTORY_SEPARATOR . $model->avatar)) {
Log::error('Error while saving avatar image', null, __METHOD__);
$this->error('Sorry! There was an error while uploading the avatar image. Contact administrator about this problem.');
}
}
Log::info('Profile updated', !empty($model->id) ? $model->id : '', __METHOD__);
$this->success('Your profile details have been updated.');
return $this->refresh();
} else {
$model->current_password = null;
}
}
return $this->render('forum', ['model' => $model, 'user' => User::findOne(Yii::$app->user->id)]);
}