How to fix "Fatal error: Interface

How to fix "Fatal error: Interface ‘Zend\ModuleManager\Feature\AutoloaderProviderInterface’ not found
I am creating a module on ZF2 .

I tried different ways creating Module.php , but am not getting output. Not sure where i am getting wrong.

<?php

namespace Admin;

use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
use Zend\ModuleManager\Feature\ConfigProviderInterface;

class Module implements AutoloaderProviderInterface, ConfigProviderInterface
{  
    public function getAutoloaderConfig()
    {  
        return array(
                    'Zend\Loader\StandardAutoloader' => array(
                'namespaces' => array(
                    __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
                ),
            ),
        );
    }
public function getConfig()
    {
        return include __DIR__ . '/../config/module.config.php';
    }
}

This is the error message i am getting :

Fatal error: Interface ‘Zend\ModuleManager\Feature\AutoloaderProviderInterface’ not found in C:\xampp\htdocs\project\module\Admin\src\Module.php on line 8

Is zendframework/zend-modulemanager in your composer.lock and in vendor/zendframework?

Did you include __DIR__ . '/vendor/autoload.php somewhere at the startup of your application?

Is zendframework/zend-modulemanager in your composer.lock and in vendor/zendframework ?

  • Yes, it is.

Did you include __DIR__ . '/vendor/autoload.php somewhere at the startup of your application?

  • Yes, i did create the file as admin.php and previously tried with include __DIR__ . '/vendor/autoload.php - but was getting errors as below :

Warning : include(C:\xampp\htdocs\project\module\Admin/…/vendor/autoload.php): failed to open stream: No such file or directory in C:\xampp\htdocs\project\module\Admin\admin.php on line 18

Warning : include(): Failed opening ‘C:\xampp\htdocs\project\module\Admin/…/vendor/autoload.php’ for inclusion (include_path=‘C:\xampp\php\PEAR’) in C:\xampp\htdocs\project\module\Admin\admin.php on line 18

Not sure, how to go through…

Silly idea, try to add another ‘…/’ to the beginning of your include path or move the include to your index.php within the public folder.

Warning : include(C:\xampp\htdocs\project\module\Admin/…/vendor/autoload.php)

I can see three dots in the path between Admin and vendor which may cause the trouble!

FYI: I typed 2 and get 3 in return :slight_smile:

I have tried, but didn’t work. Also when i added:

“autoload”: {
“psr-4”: {
“Admin\”: “module/Admin/src/”
}
},
in composer.json

I get below message when i run composer update on command line

Key autoload is a duplicate in ./composer.json

You can compare your composer.json with the quick start tutorial or the skeletion application:

https://docs.zendframework.com/tutorials/getting-started/modules/#autoloading

Followed, and now no message appears in command, but i start getting new errors as below:

Error

File:

C:\xampp\htdocs\project\vendor\zendframework\zend-servicemanager\src\Factory\InvokableFactory.php:30

Message:

Class 'Admin\Controller\IndexController' not found

Stack trace:

#0 C:\xampp\htdocs\project\vendor\zendframework\zend-servicemanager\src\ServiceManager.php(764): Zend\ServiceManager\Factory\InvokableFactory->__invoke(Object(Zend\ServiceManager\ServiceManager), 'Admin\\Controlle...', NULL)
#1 C:\xampp\htdocs\project\vendor\zendframework\zend-servicemanager\src\ServiceManager.php(200): Zend\ServiceManager\ServiceManager->doCreate('Admin\\Controlle...')
#2 C:\xampp\htdocs\project\vendor\zendframework\zend-servicemanager\src\AbstractPluginManager.php(152): Zend\ServiceManager\ServiceManager->get('Admin\\Controlle...')
#3 C:\xampp\htdocs\project\vendor\zendframework\zend-mvc\src\DispatchListener.php(102): Zend\ServiceManager\AbstractPluginManager->get('Admin\\Controlle...')
#4 C:\xampp\htdocs\project\vendor\zendframework\zend-eventmanager\src\EventManager.php(322): Zend\Mvc\DispatchListener->onDispatch(Object(Zend\Mvc\MvcEvent))
#5 C:\xampp\htdocs\project\vendor\zendframework\zend-eventmanager\src\EventManager.php(179): Zend\EventManager\EventManager->triggerListeners(Object(Zend\Mvc\MvcEvent), Object(Closure))
#6 C:\xampp\htdocs\project\vendor\zendframework\zend-mvc\src\Application.php(332): Zend\EventManager\EventManager->triggerEventUntil(Object(Closure), Object(Zend\Mvc\MvcEvent))
#7 C:\xampp\htdocs\project\public\index.php(40): Zend\Mvc\Application->run()
#8 {main}

That could be as simple as:

  • namespace typed wrong in your controller
  • IndexController.php missing under /module/Admin/src/Controller

Thank you very much, works well now.

I created 2 more modules and did like below:

"autoload": {
        "psr-4": {
            "Application\\": "module/Application/src/",
            "Admin\\": "module/Admin/src/",
            "User\\": "module/User/src/",
            "Vendor\\": "module/Vendor/src/"
        }
    },

But only last vendor module is working, and other two user and admin module are not working. So is that i will require to create different autoload snippet for admin and user module and add in composer.json ?

Have you create the module classes?
Compare with: Modules - Tutorials - Zend Framework Docs

Have you register your modules?
Compare with: Modules - Tutorials - Zend Framework Docs

And do not forget the related Composer command:

$ composer dump-autoload

Compare with: Modules - Tutorials - Zend Framework Docs

Yes, have created module classes and registered modules, already followed whatever was suggested by you and repeated same again, but still same results. Is that i am missing something?

Another option could be that you have module_map_cache_enabled in application.config.php set to true.
In that case it can’t hurt to go to the data/cache/ directory and just delete all files starting with "module-".