0
votes

started with a new ZF2 project an get following error

Argument 1 passed to ZendDeveloperTools\Module::init() must implement interface Zend\ModuleManager\ModuleManagerInterface, null given, called in /vendor/zendframework/zend-modulemanager/src/Listener/InitTrigger.php on line 33 and defined in /vendor/zendframework/zend-developer-tools/src/ZendDeveloperTools/Module.php on line 34

It doesn't matter which Module is first in application.config.php I always got this error.

1
If you do not load ZendDeveloperTools, everything works fine? - Pradeep
No, it doesn't matter which module is first... - cwhisperer

1 Answers

0
votes

This is mine Module.php file. The error is saying that you need to pass a ModuleManagerInterface as first parameter in your init method. That init method has an interface. Have a look at the Zend\ModuleManager\Feature\*Interface.php files and you will see your mistake.

namespace Application;

use Zend\Mvc\MvcEvent;
use Zend\EventManager\EventInterface;
use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
use Zend\ModuleManager\Feature\ConfigProviderInterface;
use Zend\ModuleManager\Feature\BootstrapListenerInterface;
use Zend\ModuleManager\Feature\InitProviderInterface;
use Zend\ModuleManager\ModuleManagerInterface;

class Module implements AutoloaderProviderInterface, ConfigProviderInterface, BootstrapListenerInterface, InitProviderInterface
{
    /**
     * Setup module layout
     *
     * @param  $moduleManager ModuleManager
     */
    public function init(ModuleManagerInterface $moduleManager)
    {
        $moduleManager->getEventManager()->getSharedManager()->attach(__NAMESPACE__, MvcEvent::EVENT_DISPATCH, function (MvcEvent $e) {
            $e->getTarget()->layout('layout/layout');
        });
    }

    /**
     * Listen to the bootstrap event
     *
     * @param EventInterface $e
     */
    public function onBootstrap(EventInterface $e)
    {
    }

    /**
     * @return array|\Traversable
     */
    public function getConfig()
    {
        return include __DIR__.'/config/module.config.php';
    }

    /**
     * Return an array for passing to Zend\Loader\AutoloaderFactory.
     *
     * @return array
     */
    public function getAutoloaderConfig()
    {
        return [
            'Zend\Loader\ClassMapAutoloader' => [
                __DIR__.'/autoload_classmap.php',
            ],
            'Zend\Loader\StandardAutoloader' => [
                'namespaces' => [
                    __NAMESPACE__ => __DIR__.'/src/'.__NAMESPACE__,
                ],
            ],
        ];
    }
}