Yii2 模块化调用Module失败

joson_chan 发布于 2015/09/23 17:19
阅读 4K+
收藏 0
Yii

一、错误信息如下:

Unknown Classyii\base\UnknownClassException

Unable to find 'app\modules\user\UserModule' in file: E:\www\test\basic/modules/user/UserModule.php. Namespace missing?

  • 1. in E:\www\test\basic\vendor\yiisoft\yii2\BaseYii.php at line 291
  • 2. yii\BaseYii::autoload('app\modules\user\UserModule')
  • 3. spl_autoload_call('app\modules\user\UserModule')
  • 4. in E:\www\test\basic\vendor\yiisoft\yii2\di\Container.php at line 415 – ReflectionClass::__construct('app\modules\user\UserModule')
  • 5. in E:\www\test\basic\vendor\yiisoft\yii2\di\Container.php at line 358 yii\di\Container::getDependencies('app\modules\user\UserModule')
  • 6. in E:\www\test\basic\vendor\yiisoft\yii2\di\Container.php at line 151 yii\di\Container::build('app\modules\user\UserModule', ['user', yii\web\Application], [])
  • 7. in E:\www\test\basic\vendor\yiisoft\yii2\BaseYii.php at line 344 yii\di\Container::get('app\modules\user\UserModule', ['user', yii\web\Application], [])
  • 8. in E:\www\test\basic\vendor\yiisoft\yii2\base\Module.php at line 354 yii\BaseYii::createObject(['class' => 'app\modules\user\UserModule'], ['user', yii\web\Application])
  • 9. in E:\www\test\basic\vendor\yiisoft\yii2\base\Module.php at line 511 yii\base\Module::getModule('user')
  • 10. in E:\www\test\basic\vendor\yiisoft\yii2\base\Module.php at line 449 yii\base\Module::createController('user/user/userList')
  • 11. in E:\www\test\basic\vendor\yiisoft\yii2\web\Application.php at line 84 yii\base\Module::runAction('user/user/userList', ['r' => 'user/user/userList'])
  • 12. in E:\www\test\basic\vendor\yiisoft\yii2\base\Application.php at line 375 yii\web\Application::handleRequest(yii\web\Request)
  • 13. in E:\www\test\basic\web\index.php at line 12 yii\base\Application::run()
    6 7 8 9 10 11 12
    require(__DIR__ . '/../vendor/autoload.php'); require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php'); $config = require(__DIR__ . '/../config/web.php');
     
    (new yii\web\Application($config))->run()


二、web.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' => '123456',
        ],
        'cache' => [
            'class' => 'yii\caching\FileCache',
        ],
        'user' => [
            'identityClass' => 'app\models\User',
            'enableAutoLogin' => true,
        ],
        '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'),
    ],
    'params' => $params,
    'modules' => [
        'user' => [
            'class' => 'app\modules\user\UserModule',
        ],
        'doctor' => [
            'class' => 'app\modules\doctor\DoctorModule',
        ],
    ],
];


三、项目结构如下:


四、UserModule代码如下

<?php
    namespace app\modlues\user;
    use yii\base\Module;
    
    class UserModule extends Module{
        public function init(){
            parent::init();
            $this->params['foo'] = 'bar';
        }
    }

加载中
0
游走的鱼

namespace app\modlues\user;

单词写错了啊 

返回顶部
顶部