user2406735
user2406735

Reputation: 245

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

Upvotes: 0

Views: 2573

Answers (3)

HappyCoder
HappyCoder

Reputation: 6155

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!

Upvotes: 0

Lauren Zonneveld
Lauren Zonneveld

Reputation: 683

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.

Upvotes: 0

Tim Fountain
Tim Fountain

Reputation: 33148

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 [email protected]:neilime/zf2-mobile-detect.git Neilime/MobileDetect

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

Upvotes: 1

Related Questions