2012/9/18 Robert Basic <[email protected]>
> On 17 September 2012 17:14, Matthew Weier O'Phinney <[email protected]>
> wrote:
> >
> > I personally have been recommending the first way.
>
> Any example for getting controllers via factories? I've been through
> the docs, code, tests, examples, but fail to figure it out :( I can
> get anything else to work via factories, but not controllers. The only
> way I can get controllers is using the 'controllers' => array(
> 'invokables' => array( ... )) stuff, but that doesn't allow me to
> inject dependencies.
I agree with Matthew, I prefer injecting dependencies in my controllers too.
If you have module class with a getControllerConfig() method, you could
return factory configuration as well. I usually include the controller
factories from a separate file:
public function getControllerConfig()
{
return include __DIR__ . '/config/controller.config.php';
}
Such controller.config.php can look like this:
<?php
use MyModule\Controller;
return array(
'factories' => array(
'MyModule\Controller\FooController' => function($sm) {
$service =
$sm->getServiceLocator()->get('MyModule\Service\DependencyClass');
$controller = new Controller\FooController($service);
return $controller;
},
),
);
--
Jurian Sluiman