嗨我在尝试在控制器上注入依赖项时遇到错误。
警告:缺少User \ Controller \ LoginController :: __ construct()的参数1,在第170行的/var/www/html/engsvc_dev/vendor/zendframework/zendframework/library/Zend/ServiceManager/AbstractPluginManager.php中调用在第23行的/var/www/html/engsvc_dev/module/User/src/User/Controller/LoginController.php中定义
Module.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){
}
module.config.php
"invokables" => array(
"User" => "User\Controller\LoginController",
"Login" => "User\Controller\LoginController"
),
答案 0 :(得分:0)
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;
},
),
);
}
控制器
class LoginController extends AbstractActionController{
protected $globalConfig;
protected $UserModuleSetup;
public function __construct($config){
}
module.config.php
"invokables" => array(
"User" => "User\Controller\LoginController",
),