0

嗨,我在尝试在我的控制器上注入依赖项时遇到错误。

警告:缺少 User\Controller\LoginController::__construct() 的参数 1,在 /var/www/html/engsvc_dev/vendor/zendframework/zendframework/library/Zend/ServiceManager/AbstractPluginManager.php 第 170 行调用并在 /第 23 行的 var/www/html/engsvc_dev/module/User/src/User/Controller/LoginController.php

模块.php

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

控制器

class LoginController extends AbstractActionController{

protected $globalConfig;

protected $UserModuleSetup;

public function __construct($config){

}

模块.config.php

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

1 回答 1

0

模块.php

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

控制器

class LoginController extends AbstractActionController{

protected $globalConfig;

protected $UserModuleSetup;

public function __construct($config){

}

模块.config.php

    "invokables" => array(
    "User" => "User\Controller\LoginController",
),
于 2016-04-14T00:00:48.027 回答