yii2-user 组件的使用

作者: guanguans | 来源:发表于2018-01-29 16:04 被阅读14次

    1. 安装

    composer require "dektrium/yii2-user:0.9.*@dev"
    

    2. 配置

    'modules' => [
        'user' => [
            'class' => 'dektrium\user\Module',
            'confirmWithin' => 21600,
            'cost' => 12,
            'admins' => ['admin']
        ],
    ],
    

    3. 注意

    同时删除本来的user配置
    此外要注意自己写的控制器,model,数据库这些都不能有user
    最后执行$ php yii migrate/up --migrationPath=@vendor/dektrium/yii2-user/migrations
    这样就安装完毕。
    

    4. 使用yii2-user

    下面是对应功能的url,其余使用和yii2自带的user差不多的

    • /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

    例如:

    <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>
    

    相关文章

      网友评论

      • 3630cd916cea:如放入common\modules下面呢。我这边总报错。
        guanguans:建议你先看下文档:https://github.com/dektrium/yii2-user/blob/master/docs/README.md,还是不行的话,可以私信我。

      本文标题:yii2-user 组件的使用

      本文链接:https://www.haomeiwen.com/subject/xdgxzxtx.html