我正在尝试将 yii2-user 模块安装并配置到我的 yii2 基本应用程序中。但它不起作用:
首先将其添加到composer.json文件中:
"dektrium/yii2-user": "*"
并更新了作曲家。然后只需将此代码添加到 $config 中,而不是在 config/web.php 文件中的组件部分中:
'modules' => [
'user' => [
'class' => 'dektrium\user\Module',
],
],
然后将其添加到layouts/main.php :
$navItems=[
['label' => 'Home', 'url' => ['/site/index']],
['label' => 'Status', 'url' => ['/status/index']],
['label' => 'About', 'url' => ['/site/about']],
['label' => 'Contact', 'url' => ['/site/contact']]
];
if (Yii::$app->user->isGuest) {
array_push($navItems,['label' => 'Sign In', 'url' => ['/user/login']],['label' => 'Sign Up', 'url' => ['/user/register']]);
} else {
array_push($navItems,['label' => 'Logout (' . Yii::$app->user->identity->username . ')',
'url' => ['/site/logout'],
'linkOptions' => ['data-method' => 'post']]
);
}
echo Nav::widget([
'options' => ['class' => 'navbar-nav navbar-right'],
'items' => $navItems,
]);
我还有两个菜单按钮:“登录”和“注册” 然后当我尝试输入这个网址时:
mysite/index.php?r=用户%2Fregistration%2Fregister
它来了:
Class 'yii\web\AccessControl' not found
in vendor/dektrium/yii2-user/controllers/RegistrationController.php at line 34
或者当我点击应用程序中的登录按钮时,出现找不到页面文件
我包括
yii\filters\AccessControl
班级
而不是
yii\web\AccessControl
班级
这对我有用