Php zf2新模块控制器在使用工厂时解析为无效的控制器类或别名

Php zf2新模块控制器在使用工厂时解析为无效的控制器类或别名,php,zend-framework,zend-framework2,Php,Zend Framework,Zend Framework2,我的应用程序模块配置中包含以下内容: 'controllers' => [ 'factories' => [ Application\Controller\IndexController::class => Application\Controller\IndexControllerFactory::class ], ], 这个很好用。现在我是我的服务模块我有几乎相同的: 'controllers' =>

我的应用程序模块配置中包含以下内容:

'controllers' => [
        'factories' => [
            Application\Controller\IndexController::class => Application\Controller\IndexControllerFactory::class
        ],
    ],
这个很好用。现在我是我的
服务模块
我有几乎相同的:

'controllers' => array(
                    /**
                    'invokables' => array(
                            'Serve\Controller\Index' => 'Serve\Controller\IndexController',
                    ),
                    */

                    'factories' => array(
                            Controller\IndexController::class => Serve\Controller\IndexControllerFactory::class
                    )

            ),
当我加载主页时,我通过服务控制器的api访问。这样做时,我会在主页上看到这个问题:

service\Controller\Index(解析为无效的控制器类或别名:service\Controller\Index)

就像我说的,我是通过api访问serve控制器的,所以当通过系统作为api请求时,这可能是一个设置问题

有趣的是,当我这样做时,它会起作用:

'controllers'=>array(
    'invokables' => array(
                    'Serve\Controller\Index' => 'Serve\Controller\IndexController',
            )),
不确定这里出了什么问题

更新:

这似乎有效:

'factories' => array(
                    'Serve\Controller\Index' => IndexControllerFactory::class
            )       

但是,我想使用
::class
语法当您映射到控制器时,问题在于路由配置中:
service\controller\Index
,但您可能从未在
module.config
中使用该特定键注册该控制器,或者您对键“controller”使用了错误的值在控制器映射中指定FQCN时,在路由中

//module.config
“别名”=>[
'Serve\Controller\Index'=>Serve\Controller\IndexController:class,
],
“工厂”=>[
Serve\Controller\IndexController:class=>Serve\Controller\IndexController工厂::class,
],
或者,在路由配置中,不要使用
service\Controller\Index
,而是使用FQCN,以便它直接使用工厂而不是您设置的别名。比如:

// route.config
'serve' => [
    'type' => 'literal',
    'options' => [
        'route' => '/serve',
        'defaults' => [
            'controller' => Serve\Controller\IndexController::class,
            'action'     => 'index',
       ],
    ],
],
我一直在用FQCN在工厂映射中映射我的类,如果我想用另一个名称调用它们,则添加别名。因此,您现在可以使用FQCN或其任何别名,如:
service\Controller\Index