0
votes

Hi I am having errors trying to inject dependencies on my controllers.

Warning: Missing argument 1 for User\Controller\LoginController::__construct(), called in /var/www/html/engsvc_dev/vendor/zendframework/zendframework/library/Zend/ServiceManager/AbstractPluginManager.php on line 170 and defined in /var/www/html/engsvc_dev/module/User/src/User/Controller/LoginController.php on line 23

Module.php

    public function getControllerConfig(){
    return array(
        'factories' => array(
            'Login' => function ($sm) {
                $locator = $sm->getServiceLocator();
                $controller = new LoginController($locator->get("Config"));
                return $controller;
            },
        ),
    );
}

Controller

class LoginController extends AbstractActionController{

protected $globalConfig;

protected $UserModuleSetup;

public function __construct($config){

}

module.config.php

    "invokables" => array(
    "User" => "User\Controller\LoginController",
    "Login" => "User\Controller\LoginController"
),
1
I guess that your Login definition in module.config.php is overriding the definition in Module.php. Try to remove the Login line in module.config.phpmarcosh
I've already tried that earlier. that resulted to this error Fatal error: Class 'User\LoginController' not found in /var/www/html/engsvc_dev/module/User/Module.php on line 39tom_cruz
Maybe because you call "User" without config passed to constructorchaoss88
that fix it. Thanks!tom_cruz
please set this topic as closed or delete it, or auto answer it.Unex

1 Answers

0
votes

Module.php

    public function getControllerConfig(){
    return array(
        'factories' => array(
            'Login' => function ($sm) {
                $locator = $sm->getServiceLocator();
                $controller = new User\Controller\LoginController($locator->get("Config"));
                return $controller;
            },
        ),
    );
}

Controller

class LoginController extends AbstractActionController{

protected $globalConfig;

protected $UserModuleSetup;

public function __construct($config){

}

module.config.php

    "invokables" => array(
    "User" => "User\Controller\LoginController",
),