ZF2 - Missing argument 1 for XXXController::__construct()

I am trying to use a factory to create a controller instance:

class AuthenticationController extends AbstractActionController
    implements ControllerProviderInterface 
{
    private $loginLogoutService;

    public function __construct($lls)
    {
        $this->loginLogoutService = $lls;
    }

    public function getControllerConfig() {
        return array(
            'factories' => array(
                'Main\Controller\Authentication' => function(ControllerManager $cm) {
                    $sm   = $cm->getServiceLocator();
                    $depA = $sm->get('LoginLogoutService');
                    $controller = new AuthenticationController($depA);
                    return $controller;
                },
            ),
        );
    }

But I am getting an error message:

Warning: Missing argument 1 for Main\Controller\AuthenticationController::__construct()

Why isn't the factory used to create the controller?

Upvotes: 0

Views: 409

Answers (1)

Tim Fountain
Tim Fountain

Reputation: 33148

getControllerConfig() should be in your Module.php, not in the controller itself. Everything else looks okay.

Upvotes: 1

Related Questions