當前位置: 首頁>>代碼示例>>PHP>>正文


PHP User::findOne方法代碼示例

本文整理匯總了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.'));
         }
     }
 }
開發者ID:keltstr,項目名稱:yii2-podium,代碼行數:9,代碼來源:Meta.php

示例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]);
 }
開發者ID:aekkapun,項目名稱:yii2-podium,代碼行數:14,代碼來源:AdminController.php

示例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)]);
 }
開發者ID:keltstr,項目名稱:yii2-podium,代碼行數:50,代碼來源:ProfileController.php


注:本文中的bizley\podium\models\User::findOne方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。