1
votes

I have the following in my application module config:

'controllers' => [
        'factories' => [
            Application\Controller\IndexController::class => Application\Controller\IndexControllerFactory::class
        ],
    ],

this works fine. now im my serve module i have pretty much the same:

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

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

            ),

when i load the homepage i access through an api the serve controller. when doing so i get this problem on the homepage:

Serve\Controller\Index (resolves to invalid controller class or alias: Serve\Controller\Index)

like i said im accessing the serve controller through an api so it might be a setup issue when requesting through the system as an api.

Whats interesting is when i do this it works:

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

not sure whats wrong here

UPDATE:

This seems to work:

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

however id like to use ::class syntax

1

1 Answers

1
votes

The problem lies within your route config as you map to the controller: Serve\Controller\Index but you either never registered that controller with that specific key within your module.config or you are using the wrong value for the key "controller" within your route as you specified the FQCN within your controller mapping.

// module.config
'aliases' => [
    'Serve\Controller\Index' => Serve\Controller\IndexController:class,
],
'factories' => [
    Serve\Controller\IndexController:class => Serve\Controller\IndexControllerFactory::class,
],

Or within your route configs don't use the Serve\Controller\Index but use the FQCN, so that it uses the Factory directly instead of the alias you've set up. Like:

// route.config
'serve' => [
    'type' => 'literal',
    'options' => [
        'route' => '/serve',
        'defaults' => [
            'controller' => Serve\Controller\IndexController::class,
            'action'     => 'index',
       ],
    ],
],

I keep mapping my classes in the factory mapping with the FQCN and add aliases if I want to call them by another name. So you are now able to either use the FQCN or any of its aliases, like: Serve\Controller\Index