Search code examples
phpzend-frameworkzf3

ZF3 controller not found in module.php


I am very new in Zend Fw 3. I followed https://docs.zendframework.com/tutorials/ I added the controller config in module.php

public function getControllerConfig(){
    return[
        'factories' = >[
            Controller\DocumentController::class = > function($container) {
                return new Controller\DocumentController(
                    $container->get(Model\DocumentTable::class)
                );
            },
        ],
    ];
}

By running this, I faced this error:

ERROR


Solution

  • <?php
         namespace Document;
    
         use Zend\Db\ResultSet\ResultSet;
         use Zend\Db\TableGateway\TableGateway;
         use Zend\ModuleManager\Feature\ConfigProviderInterface;
    
         class Module implements ConfigProviderInterface
         {
    
    
            public function getConfig()
            {
               return include __DIR__ . '/../config/module.config.php';
            }
    
            public function getServiceConfig()
            {
               return [
                    'factories' => [
                            Model\DocumentTable::class => function($container) {
                                $tableGateway = $container->get(Model\DocumentTableGateway::class);
                                return new Model\DocumentTable($tableGateway);
                            },
                            Model\DocumentTableGateway::class => function ($container) {
                                $dbAdapter = $container->get(AdapterInterface::class);
                                $resultSetPrototype = new ResultSet();
                                $resultSetPrototype->setArrayObjectPrototype(new Model\Document());
                                return new TableGateway('document', $dbAdapter, null, $resultSetPrototype);
                            },
                    ],
               ];
            }
    
            public function getControllerConfig()
            {
               return [
                    'factories' => [
                            Controller\DocumentController::class => function($container) {
                                return new Controller\DocumentController(
                                        $container->get(Model\DocumentTable::class)
                                );
                            },
                    ],
               ];
            }
    
    }