时间:2021-07-01 10:21:17 帮助过:121人阅读
<?php namespace app\models; use dektrium\user\models\User as BaseUser; use Yii; class User extends BaseUser // 这记得要继承 { }
'user' => [ 'identityClass' => 'app\models\User', 'loginUrl' => ['site/login'], 'enableAutoLogin' => true, ],
'modules' => [ 'v1' => [ 'class' => 'app\modules\v1\Module', ], 'admin' => [ 'class' => 'mdm\admin\Module', 'layout' => 'left-menu',//yii2-admin的导航菜单 ], // 'rbac' => 'dektrium\rbac\RbacWebModule', 'rbac' => [ 'class' => 'dektrium\rbac\Module', ], 'user' => [ 'class' => 'dektrium\user\Module', 'enableRegistration' => false, 'enableConfirmation' => false, 'enableUnconfirmedLogin' => true, 'enablePasswordRecovery' => true, 'confirmWithin' => 21600, 'rememberFor' => 1209600, //如果没有点击记住密码则默认保持1天的登录时间 'admins' => ['admin'], 'modelMap' => [ 'User' => 'app\models\User', // 'Profile' => 'app\models\Profile', ], ], ],
Yii::$app->user->login($user, $duration);
此时可以
Yii::$app->user->identity->id
Yii::$app->user->identity->name
相关推荐:
Laravel管道的深入解析(代码)
PHP自定义递归函数如何实现数组转JSON的功能
以上就是yii2中user的用法介绍(附代码)的详细内容,更多请关注Gxl网其它相关文章!