Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/266.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Symfony 4.0 Translator接口未在类中自动连接_Php_Symfony_Autowired_Symfony4 - Fatal编程技术网

Php Symfony 4.0 Translator接口未在类中自动连接

Php Symfony 4.0 Translator接口未在类中自动连接,php,symfony,autowired,symfony4,Php,Symfony,Autowired,Symfony4,我在带有自动布线的控制器中使用了TranslatorInterface,它工作正常: public function __construct(LoggerInterface $logger, TranslatorInterface $translator) { $this->_logger = $logger; $this->_translator = $translator; } 但是,当我尝试在另一个类中将

我在带有自动布线的控制器中使用了
TranslatorInterface
,它工作正常:

public function __construct(LoggerInterface $logger,
                            TranslatorInterface $translator)
{
    $this->_logger = $logger;
    $this->_translator = $translator;
}
但是,当我尝试在另一个类中将此接口与自动布线一起使用时,它不起作用:

class MunicipalityValidator
{
    private $_translator;
    private $_validator;

    public function __construct(TranslatorInterface $translator,
                                ValidatorInterface $validator)
    {
        $this->_translator = $translator;
        $this->_validator = $validator;
    }
    //...
}
我收到以下错误消息:

FatalThrowableError
Type error: Too few arguments to function App\Validator\MunicipalityValidator::__construct(),
0 passed in /var/www/html/sf4proj/src/Factory/MunicipalityFactory.php on line 34 and
exactly 2 expected
你对这个问题有什么想法吗


谢谢。

您可以发布您是如何使用市政验证程序的吗?只需$validator=new MunicipalityValidator();这就是它不起作用的原因。您应该将它作为一个服务使用,从容器中获取或注入它,或者,如果您使用这种方式,则必须显式地将对象传递给构造函数库。这是否意味着我必须为我的验证器创建一个服务,并使用$this->get('unicity_validator')->myMethod(arg1、arg2、arg3…)调用它?请查看和