【问题标题】:Installing Yii2 User Management Module安装 Yii2 用户管理模块
【发布时间】:2015-10-17 17:27:33
【问题描述】:

我正在尝试将用户管理模块安装到 Yii2 应用程序(供参考,即模块:https://github.com/webvimark/user-management)。

假设我不知道作曲家是什么,但我安装了它并设法使它适用于安装。我正在运行本地服务器,因为应用程序位于我无法访问 SSH 终端的共享主机上。

我进行了 README 文件中指定的所有更改并运行了composer require --prefer-dist webvimark/module-user-management "*"。它发挥了作用,就我所见,它在应用程序的供应商文件夹中生成了一堆目录。我将它们上传到服务器,但现在当我尝试加载主页时,出现错误:

类 webvimark\modules\UserManagement\components\UserConfig 没有 存在

文件目前在这里:

APPLICATION_HOME\public_html\basic\vendor\webvimark\module-user-management\components

但应用程序似乎无法找到它。我没有模块目录(就像以前的 Yii 版本一样),我的所有配置和其他文件都按照自述文件中的指定进行了更新。任何想法出了什么问题?

编辑:以防万一,添加我的 config/web.php:

<?php

$params = require(__DIR__ . '/params.php');

$config = [
    'id' => 'basic',
    'basePath' => dirname(__DIR__),
    'bootstrap' => ['log'],
    'components' => [
        'request' => [
            // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
            'cookieValidationKey' => 'SOME_RANDOM_STRING',
        ],
        'cache' => [
            'class' => 'yii\caching\FileCache',
        ],
        /*'user' => [
            'identityClass' => 'app\models\User',
            'enableAutoLogin' => true,
        ],*/
        'user' => [
            'class' => 'webvimark\modules\UserManagement\components\UserConfig',

            // Comment this if you don't want to record user logins
            'on afterLogin' => function($event) {
                \webvimark\modules\UserManagement\models\UserVisitLog::newVisitor($event->identity->id);
            }
        ],
        'errorHandler' => [
            'errorAction' => 'site/error',
        ],
        'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            // send all mails to a file by default. You have to set
            // 'useFileTransport' to false and configure a transport
            // for the mailer to send real emails.
            'useFileTransport' => true,
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
        'db' => require(__DIR__ . '/db.php'),
        'i18n' => [
            'translations' => [
                'frontend*' => [
                    'class' => 'yii\i18n\PhpMessageSource',
                    'basePath' => '@common/messages',
                ],
                'backend*' => [
                    'class' => 'yii\i18n\PhpMessageSource',
                    'basePath' => '@common/messages',
                ],
            ],
        ],
    ],
    'modules'=>[
        'user-management' => [
            'class' => 'webvimark\modules\UserManagement\UserManagementModule',

            // Here you can set your handler to change layout for any controller or action
            // Tip: you can use this event in any module
            'on beforeAction'=>function(yii\base\ActionEvent $event) {
                    if ( $event->action->uniqueId == 'user-management/auth/login' )
                    {
                        $event->action->controller->layout = 'loginLayout.php';
                    };
                },
        ],
    ],            
    'params' => $params,

];

if (YII_ENV_DEV) {
    // configuration adjustments for 'dev' environment
    $config['bootstrap'][] = 'debug';
    $config['modules']['debug'] = 'yii\debug\Module';

    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = 'yii\gii\Module';
}

return $config;

【问题讨论】:

  • 给我看看你的confi/main.php
  • config/main.php 是 Yii2.0 之前的老派,但我已经编辑了问题并添加了 config/web.php。希望这会给你一个提示

标签: php yii2 yii-components


【解决方案1】:

尝试像模块而不是组件一样使用它 从组件中删除并添加模块

'modules'=>[
    'user-management' => [
        'class' => 'webvimark\modules\UserManagement\UserManagementModule',

【讨论】:

  • 它确实是作为一个模块添加的,请仔细查看 web.php 文件的末尾。例如,如果我只在文件的组件部分中注释掉用户部分,那么当我尝试登录或注销时,URL 只是“未找到”。
  • 可能是路径/命名空间问题。你正在开发什么操作系统?
  • 我个人机器上的安装是在 Windows 8.1 上。共享托管服务器正在运行,我会说基于 Linux 的操作系统上的 Apache。如果您认为这是问题所在,我可以检查具体细节?
  • 在你的 urlManager 规则中可能需要这样的东西:'login/' => 'user-management/auth/login'
猜你喜欢
  • 1970-01-01
  • 2022-01-23
  • 2015-12-02
  • 2014-01-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多