本文整理汇总了PHP中app\models\Profile::findOne方法的典型用法代码示例。如果您正苦于以下问题:PHP Profile::findOne方法的具体用法?PHP Profile::findOne怎么用?PHP Profile::findOne使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Profile
的用法示例。
在下文中一共展示了Profile::findOne方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionView
public function actionView($title)
{
$eventId = explode('-', $title)[1];
//$training = Events::find(['id' => $eventId[1]])->one();
$training = $this->findModel($eventId);
return $this->render('training', ['training' => $training, 'organizer' => Profile::findOne(['user_id' => $training['organizer_id']]), 'eventsList' => Events::find()->limit('4')->all()]);
}
示例2: updateProfile
public function updateProfile()
{
$profile = ($profile = Profile::findOne(Yii::$app->user->id)) ? $profile : new Profile();
$profile->user_id = Yii::$app->user->id;
$profile->first_name = $this->first_name;
$profile->last_name = $this->last_name;
return $profile->save() ? true : false;
}
示例3: findModel
protected function findModel($id)
{
if (($model = Profile::findOne(['user_id' => $id])) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
示例4: getUsername
/**
* @return \yii\db\ActiveQuery
*/
public function getUsername()
{
if (!Yii::$app->user->isGuest) {
$user = Yii::$app->user->getIdentity();
$id = $user->id;
$user_id = Profile::findOne(['user_id' => $id]);
return $user_id->second_name . " " . $user_id->first_name;
}
}
示例5: findModel
protected function findModel()
{
if ($model = Profile::findOne(Yii::$app->user->identity->getId())) {
$model->username = $model->user->username;
$model->email = $model->user->email;
$model->role = $model->user->role;
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
示例6: actionApprove
public function actionApprove($id)
{
$model = $this->findModel($id);
$model->is_approved = 1;
if ($profile = Profile::findOne(['user_id' => $model['psychologist_id']])) {
$profile->has_diplom = 1;
$profile->save();
}
if ($model->save()) {
return $this->redirect(['index']);
}
}
示例7: actionProfile
/**
* Profile
*/
public function actionProfile()
{
/** @var User $user */
/** @var Profile $profile */
// get user and profile
$user = $this->jwtAuth->getAuthenticatedUser();
$profile = Profile::findOne(["user_id" => $user->id]);
// update profile
if ($profile->loadPostAndSave() === false) {
return ["errors" => $profile->errors];
}
return ["success" => ["profile" => $profile]];
}
示例8: actionProfile
public function actionProfile()
{
$model = ($model = Profile::findOne(Yii::$app->user->id)) ? $model : new Profile();
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
if ($model->updateProfile()) {
Yii::$app->session->setFlash('success', 'Профиль изменен');
} else {
Yii::$app->session->setFlash('error', 'Профиль не изменен');
Yii::error('Ошибка записи. Профиль не изменен');
return $this->refresh();
}
}
return $this->render('profile', ['model' => $model]);
}
示例9: updateProfile
public function updateProfile($profile)
{
$profile = ($profile = Profile::findOne(Yii::$app->user->id)) ? $profile : new Profile();
$profile->user_id = Yii::$app->user->id;
$profile->nickname = $this->nickname;
/* a lil bit check whether the file uploaded well for both avatar and background */
if ($this->file) {
$profile->avatar = $this->file->getBaseName() . '.' . $this->file->getExtension();
}
if (isset($this->background_file)) {
$profile->background_img = $this->background_file->getBaseName() . '.' . $this->background_file->getExtension();
}
return $profile->save() ? $profile : null;
}
示例10: actionView
public function actionView($title)
{
$articleId = explode('-', $title);
$articleModel = new ArticleComments();
$model = new ArticleComments();
$model->user_id = Yii::$app->user->id;
$article = $this->findModel($articleId[1]);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->render('view', ['model' => $article, 'articleComments' => $articleModel, 'articleCommentsList' => ArticleComments::getArticleComments($articleId[1]), 'popularPosts' => Article::getPopularPosts(), 'author' => Profile::findOne(['user_id' => $article['psychologist_id']])]);
}
if ($articleId[1]) {
$articleModel->article_id = $articleId[1];
return $this->render('view', ['model' => $article, 'articleComments' => $articleModel, 'articleCommentsList' => ArticleComments::getArticleComments($articleId[1]), 'popularPosts' => Article::getPopularPosts(), 'author' => Profile::findOne(['user_id' => $article['psychologist_id']])]);
}
}
示例11: updateProfile
public function updateProfile()
{
$profile = ($profile = Profile::findOne(Yii::$app->user->id)) ? $profile : new Profile();
$profile->user_id = Yii::$app->user->id;
$profile->first_name = $this->first_name;
$profile->second_name = $this->second_name;
$profile->middle_name = $this->middle_name;
if ($profile->save()) {
$user = $this->user ? $this->user : User::findOne(Yii::$app->user->id);
$username = Yii::$app->request->post('User')['username'];
$user->username = isset($username) ? $username : $user->username;
return $user->save() ? true : false;
}
return false;
}
示例12: updateProfile
/**
* Обновление профиля
* @return bool
*/
public function updateProfile()
{
$profile = ($profile = Profile::findOne(Yii::$app->user->id)) ? $profile : new Profile();
$profile->user_id = Yii::$app->user->id;
$profile->first_name = $this->first_name;
$profile->second_name = $this->second_name;
$profile->middle_name = $this->middle_name;
// Сохранение логина
if ($profile->save()) {
$user = $this->user ? $this->user : User::findOne(Yii::$app->user->id);
$login = Yii::$app->request->post('User')['login'];
$user->login = isset($login) ? $login : $user->login;
return (bool) $user->save();
// var_dump($user->getErrors());
}
return false;
}
示例13: updateProfile
public function updateProfile()
{
$profile = ($profile = Profile::findOne(Yii::$app->user->id)) ? $profile : new Profile();
$profile->user_id = Yii::$app->user->id;
$profile->first_name = $this->first_name;
$profile->second_name = $this->second_name;
$profile->middle_name = $this->middle_name;
$profile->profile_status = $this->profile_status;
$profile->birthday = $this->birthday;
$profile->gender = $this->gender;
$user_avatar = UploadedFile::getInstance($this, 'avatar_file');
if ($user_avatar) {
$profile->avatar = 'images/avatars/' . $user_avatar->baseName . '.' . $user_avatar->extension;
$user_avatar->saveAs('images/avatars/' . $user_avatar->baseName . '.' . $user_avatar->extension);
}
return $profile->save() ? true : false;
}
示例14: actionViewProfile
public function actionViewProfile($id)
{
if (!Yii::$app->user->isGuest) {
if ($id == Yii::$app->user->id or Yii::$app->user->can('user')) {
$model = Profile::findOne($id);
if (!empty($model)) {
return $this->render('viewProfile', ['model' => $model]);
} else {
$model = new Profile();
Yii::$app->session->setFlash('success', "Профиль не заполнен. Заполните пожалустай.");
return $this->render('update-profile', ['model' => $model]);
}
} else {
Yii::$app->session->setFlash('error', 'Нет доступа!');
$this->redirect('/');
}
} else {
Yii::$app->session->setFlash('error', 'Нет доступа!');
$this->redirect('/');
}
}
示例15: createMenu
public function createMenu()
{
$menu = "";
if (!Yii::$app->user->isGuest) {
$profile = Profile::findOne(Yii::$app->user->identity->profile_id);
$menu .= "<h2><span class='label label-primary'>{$profile->name}</span></h2>";
// $menu .= "<a href='" . Url::toRoute("site/index") . "'><i class='fa fa-fw fa-home'></i><span>Home</span></a>";
$access = Access::find()->where(["profile_id" => Yii::$app->user->identity->profile_id])->all();
foreach ($access as $value) {
$module = Module::find()->where(["id" => $value->module_id])->one();
$path = "{$module->controller}/index";
$href = Url::toRoute($path);
$link = "<a href='{$href}'><i class='fa fa-fw {$module->iconfa}'></i><span>{$module->label}</span></a>";
$menu .= $link;
}
}
// if (Yii::$app->user->isGuest) {
// $menu .= "<a href='" . Url::toRoute('site/login') . "'><i class='fa fa-fw fa-sign-in'></i><span>Login</span></a>";
// } else {
// $menu .= "<a href='" . Url::toRoute('site/logout') . "' data-method='post'><i class='fa fa-fw fa-sign-out'></i><span>Logout (" . Yii::$app->user->identity->username . ")</span></a>";
// }
return $menu;
}