Home >PHP Framework >YII >How to use user component in yii2
How to use the user component in yii2
1. First install the yii2 user component
composer require "dektrium/yii2-user:0.9.*@dev"
2, and then configure it
'modules' => [ 'user' => [ 'class' => 'dektrium\user\Module', 'confirmWithin' => 21600, 'cost' => 12, 'admins' => ['admin'] ], ],
3. Notes
(Related tutorials recommended: yii framework)
Delete the original user configuration at the same time
In addition, please note that the controller, model, and database you write cannot have user
Finally execute $ php yii migrate/up --migrationPath=@vendor/dektrium/yii2-user/migrations
The installation is complete.
4. Use yii2-user
The following is the url of the corresponding function, and the rest are similar to the user that comes with yii2
/user/registration/register Displays registration form /user/registration/resend Displays resend form /user/registration/confirm Confirms a user (requires id and token query params) /user/security/login Displays login form /user/security/logout Logs the user out (available only via POST method) /user/recovery/request Displays recovery request form /user/recovery/reset Displays password reset form (requires id and token query params) /user/settings/profile Displays profile settings form /user/settings/account Displays account settings form (email, username, password) /user/settings/networks Displays social network accounts settings page /user/profile/show Displays user's profile (requires id query param) /user/admin/index Displays user management interface
For example:
<div class="login-strip"> <?php if(Yii::$app->user->isGuest){ ?> <?= Html::a("<i class='icon-plus'></i> 注 册",['/user/registration/register']); ?> | <?= Html::a("<i class='icon-signin'></i> 登 录",['/user/security/login']); ?> <?php } else { ?> <?= Html::a("<i class='icon-signout'></i> 退出",['/user/security/logout']); ?> <?php } ?> </div>
PHP Chinese website, a large number of thinkphp tutorials, welcome to learn!
The above is the detailed content of How to use user component in yii2. For more information, please follow other related articles on the PHP Chinese website!