From my Factory i am passsing serviceLocator to the controller, but it seems like ObservationFactory is not being called even i have included in the module.config.php file of the Module
Here is my ObservationController.php
class ObservationController extends AbstractActionController
{
private $em;
public function __construct($ob)
{
$this->em = $ob->get('doctrine.entitymanager.orm_default');
}
here is ObservationFactory.php
class ObservationFactory implements FactoryInterface
{
public function createService(ServiceLocatorInterface $serviceLocator)
{
$controller = new ObservationController($serviceLocator->getServicelocator());
return $controller;
}
}
and in Module.config.php
'controllers' => array(
'factories' => array(
'Observation\Controller\ObservationController' => 'Observation\Controller\ObservationFactory'
),
'invokables' => array(
'Observation\Controller\Observation'=> Controller\ObservationController::class
),
),
Missing argument 1 for Observation\Controller\ObservationController::__construct(), called in S:\xampp\htdocs\v3\vendor\zendframework\zend-servicemanager\src\AbstractPluginManager.php on line 207 and defined in S:\xampp\htdocs\v3\module\Observation\src\Observation\Controller\ObservationController.php on line 47
Notice: Undefined variable: ob in S:\xampp\htdocs\v3\module\Observation\src\Observation\Controller\ObservationController.php on line 49
Fatal error: Uncaught Error: Call to a member function get() on unknown in
ObervationController::class => ObervationControllerFactory::class
? Maybe your invokables trouble your factory. What happens if you leave out the invokables section in your controller array? – MarcelServiceLocatorInterface
into your controller just to grab the entitymanager, why wont you use proper dependency injection and just inject the entitymanager into your controller instead? – boesing