/** * Shows user's profile. * * @return \yii\web\Response * @throws \yii\web\NotFoundHttpException */ public function actionIndex() { $profile = Profile::findOne(['uid' => Yii::$app->user->id]); if ($profile == NULL) { throw new NotFoundHttpException(); } return $this->render('index', ['profile' => $profile]); }
public function actionUploadAvatar() { if (isset($_FILES['avatar'])) { $avatar = $_FILES['avatar']; $path = '../vendor/abhi1693/yii2-user/uploads/profile_image/'; $model = Profile::findOne(['uid' => Yii::$app->user->getId()]); $model->avatar = 'vendor/abhi1693/yii2-user/uploads/profile_image/' . $avatar['name']; if ($model->save()) { if (move_uploaded_file($avatar['tmp_name'], $path . $avatar['name'])) { return json_encode((object) NULL); } else { return json_encode(['error' => 'An Error Occurred. Please try again!']); } } } return json_encode(['error' => 'An Error Occurred. Please try again!']); }
<?php /** * Created by PhpStorm. * User: Abhimanyu * Date: 02-03-2015 * Time: 23:33 */ use abhimanyu\user\models\Profile; use yii\helpers\Html; use yii\widgets\Menu; /** @var $profile \abhimanyu\user\models\Profile */ $profile = Profile::findOne(['uid' => Yii::$app->user->getId()]); ?> <div class="panel panel-default"> <div class="panel-heading"><h3 class="panel-title"><?php echo Html::img(Yii::$app->homeUrl . '/../../' . $profile['avatar'], ['alt' => 'Profile Image', 'width' => 30, 'class' => 'img-rounded']); ?> <?php echo Html::encode($profile['name_first'] . ' ' . $profile['name_last']); ?> </h3></div> <div class="panel-body"> <?php echo Menu::widget(['options' => ['class' => 'nav nav-pills nav-stacked'], 'items' => [['label' => 'Profile', 'url' => ['/user/account/profile']], ['label' => 'Avatar', 'url' => ['/user/account/avatar']]]]); ?> </div> </div>
* Time: 13:58 */ use abhimanyu\user\models\Profile; use kartik\alert\AlertBlock; use kartik\grid\GridView; use yii\helpers\Html; /** @var $this \yii\web\View */ /** @var $dataProvider \abhimanyu\user\models\UserSearch */ /** @var $searchModel \abhimanyu\user\models\UserSearch */ $this->title = Yii::t('user', 'User Admin - ' . Yii::$app->name); echo AlertBlock::widget(['delay' => 5000, 'useSessionFlash' => TRUE]); ?> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => \kartik\grid\SerialColumn::className()], ['header' => '', 'value' => function ($model) { $avatar = Profile::findOne(['uid' => $model->id]); return '<div class="text-center">' . Html::img(Yii::$app->homeUrl . '/../../' . $avatar['avatar'], ['width' => 30, 'alt' => 'Profile Image']) . '</div>'; }, 'format' => 'raw'], 'username', 'email', ['attribute' => 'super_admin', 'value' => function ($model) { if ($model->super_admin == 1) { return '<div class="text-center text-success"><i class="glyphicon glyphicon-ok"></i></div>'; } else { return '<div class="text-center text-danger"><i class="glyphicon glyphicon-remove"></i></div>'; } }, 'format' => 'raw'], ['header' => 'Status', 'value' => function ($model) { return $model->isStatus; }, 'format' => 'raw'], ['class' => \kartik\grid\ActionColumn::className(), 'template' => '{confirm} {block} {update} {delete}', 'buttons' => ['confirm' => function ($url, $model) { if ($model->isConfirmed) { return Html::a('<i class="glyphicon glyphicon-ok"></i>', NULL); } else { return Html::a('<i class="glyphicon glyphicon-ok"></i>', $url, ['data-method' => 'post', 'data-confirm' => Yii::t('user', 'Are you sure you want to confirm this user?'), 'title' => Yii::t('user', 'Confirm User')]); }
public function down() { $this->dropColumn(Profile::tableName(), 'avatar'); }
<?php /** * Created by PhpStorm. * User: Abhimanyu * Date: 01-03-2015 * Time: 21:30 */ use abhimanyu\installer\helpers\enums\Configuration as Enum; use abhimanyu\user\models\Profile; use yii\bootstrap\Nav; use yii\bootstrap\NavBar; NavBar::begin(['brandLabel' => Yii::$app->config->get(Enum::APP_NAME), 'brandUrl' => Yii::$app->homeUrl, 'options' => ['class' => 'navbar-inverse navbar-fixed-top']]); if (Yii::$app->user->isGuest) { $menuItems = [['label' => 'Login', 'url' => ['/user/auth/login']]]; } else { $menuItems = [['label' => 'Home', 'url' => ['/site/index']], ['label' => 'Admin Panel', 'url' => ['/admin/index'], 'visible' => Yii::$app->user->identity->isAdmin], ['label' => Profile::findOne(['uid' => Yii::$app->user->getId()])['name_first'] ?: Yii::$app->user->identity->username, 'items' => [['label' => 'Account Settings', 'url' => ['/user/account/profile']], ['label' => 'Logout', 'url' => ['/user/auth/logout'], 'linkOptions' => ['data-method' => 'post']]]]]; } echo Nav::widget(['options' => ['class' => 'navbar-nav navbar-right'], 'items' => $menuItems]); NavBar::end();
/** * Gets user profile * * @return Profile */ public function getProfile() { return $this->hasOne(Profile::className(), ['uid' => 'id']); }
public function down() { $this->dropTable(Profile::tableName()); $this->dropTable(User::tableName()); }