Home >PHP Framework >YII >How to use user component in yii2

How to use user component in yii2

angryTom
angryTomOriginal
2020-03-19 18:14:453604browse

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=&#39;icon-plus&#39;></i> 注 册",[&#39;/user/registration/register&#39;]); ?> |
  <?= Html::a("<i class=&#39;icon-signin&#39;></i> 登 录",[&#39;/user/security/login&#39;]); ?>
  <?php
  } else {
  ?>
  <?= Html::a("<i class=&#39;icon-signout&#39;></i> 退出",[&#39;/user/security/logout&#39;]); ?>
  <?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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:What are Yii and Redis?Next article:What are Yii and Redis?