Controller not called when closing initializers
I want the doctrine entity admin to go into different classes in my ZF2 project. Thus. I have set the following initializer to mine Module.php
:
'initializers' => array(
function ($instance, $services) {
if (is_object($instance)) { // just for debugging
var_dump(get_class($instance));
}
if (!$instance instanceof EntityManagerAwareInterface) {
return;
}
$entityManager = $services->get('doctrine.entitymanager.orm_default');
$instance->setEntityManager($entityManager);
},
),
)
However, it never gets called on mine AuthController
, even if I visit that controller's site (and get a null pointer exception because the entity dispatcher was not set). Of course, the controller implements the required interface:
class AuthController extends AbstractActionController implements EntityManagerAwareInterface
Is there anything else I need to tweak so that mine is AuthController
checked for initializer closure?
At the moment I have this under invokables in module.config.php
.
'controllers' => array(
'invokables' => array(
'Auth\Controller\Auth' => 'Auth\Controller\AuthController',
),
),
When I remove it from there, the application can no longer find this class.
My debug release lists other classes that are checked for initializers, many managers and services. A short excerpt:
string(37) "Zend\\Mvc\\Controller\\ControllerManager"
string(33) "Zend\\Mvc\\Controller\\PluginManager"
string(29) "Zend\\View\\HelperPluginManager"
[...]
string(24) "Doctrine\\DBAL\\Connection"
string(26) "Doctrine\\ORM\\EntityManager"
string(41) "Zend\\Authentication\\AuthenticationService"
source to share
Try adding an initializer for the controller manager, judging by your debug output, the one you posted is for the service manager. In a similar way, you configure other managers, the method for the dispatcher manager isgetControllerConfig
public function getControllerConfig()
{
return array(
'initializers' => array(
// controller initializers here...
),
);
}
source to share