简体   繁体   中英

Zend2 Framework module could not be initialized

I am trying to install Zend2 Framework module for mobile detection. Module is called Mobile Detect. I am following instructions given on that page, so i have cloned Mobile-Detect and the entire project from first link in vendor directory via git shell. I have added 'Neilime\\MobileDetect'in application.config.php file and it shows me this error:

Fatal error: Uncaught exception 'Zend\ModuleManager\Exception\RuntimeException' with message 'Module (Neilime\MobileDetect) could not be initialized.' in 
D:\xampp\htdocs\zend2test\vendor\zendframework\zendframework\library\Zend\ModuleManager\ModuleManager.php:144 Stack trace: #0 
D:\xampp\htdocs\zend2test\vendor\zendframework\zendframework\library\Zend\ModuleManager\ModuleManager.php(85): Zend\ModuleManager\ModuleManager->loadModule('Neilime\MobileD...') #1 
[internal function]: Zend\ModuleManager\ModuleManager->onLoadModules(Object(Zend\ModuleManager\ModuleEvent)) #2 
D:\xampp\htdocs\zend2test\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(464): call_user_func(Array, Object(Zend\ModuleManager\ModuleEvent)) #3 
D:\xampp\htdocs\zend2test\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(208): Zend\EventManager\EventManager->triggerListeners('loadModules', Object(Zend\ModuleManager\ModuleEvent), NULL) #4 
D:\xampp\htdocs\zend2test\vendor\zendframework\zendframework\libra in 
D:\xampp\htdocs\zend2test\vendor\zendframework\zendframework\library\Zend\ModuleManager\ModuleManager.php on line 144

I'd recommend using the composer installation method given in the docs instead.

If you really want to stick with git clone, try:

git clone git@github.com:neilime/zf2-mobile-detect.git Neilime/MobileDetect

from the vendor folder instead, which should clone it to the correct path.

The error means that the module cannot be found. This is probably an autoloading issue.

See the following question to see how to add the correct autoload config. https://stackoverflow.com/a/14980942/902466

In your case it'll be something like the following edit in init_autoloader.php:

Zend\Loader\AutoloaderFactory::factory(array(
    'Zend\Loader\StandardAutoloader' => array(
        'autoregister_zf' => true,
        'namespaces' => array(
            'Neilime\MobileDetect'   => __DIR__ . '/vendor/neilime/zf2-mobile-detect',
        ),
    ),
));

Edit: Obsiously using Composer would be the best idea since it will create the autoload configuration for you.

I had a similar problem. The fix was a case issue:

Make sure your **M**odule.php file is written with a capital M otherwise the file may not be found. This took me a day to bug test so I really hope I save someone the same trouble!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM