首页  >  文章  >  php框架  >  yii2怎么使用user组件

yii2怎么使用user组件

angryTom
angryTom原创
2020-03-19 18:14:453562浏览

yii2怎么使用user组件

yii2怎么使用user组件    

1、首先安装yii2 user组件

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

2、然后进行配置

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

3、注意事项

(相关教程推荐:yii框架

同时删除本来的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=&#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中文网,大量thinkphp教程,欢迎学习!

以上是yii2怎么使用user组件的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn