Php7中的Symfony 2 Translator对象错误

时间:2017-10-10 08:32:10

标签: php symfony

此代码之前在php 5.4中工作,但在升级到php7之后我收到此错误:

  

类型错误:传递给dell \ Bundle \ dellbundles \ ot \ otdell :: __ construct()的参数6必须是Symfony \ Bundle \ FrameworkBundle \ Translation \ Translator的实例,给出Symfony \ Component \ Translation \ DataCollectorTranslator的实例,在/var/www/dellprj/vendor/dfolder/dfolderbundles/dell/Bundle/otde/Controller/otdellController.php中调用

 $translator = $this->get('translator');

 $myvar = new OtDell($this, $this->container, $viewParameters, $logger, $request, $translator);

表示问题$translator。无论如何,这是OtDell类的代码:

 public function __construct(Controller $controller, ContainerInterface $container, array $viewParameters, LoggerInterface $logger, Request $request, Translator $translator)
    {......}

这是$ translator变量的var_dump:

enter image description here

提前致谢。

1 个答案:

答案 0 :(得分:0)

导入翻译界面: 使用Symfony \ Component \ Translation \ TranslatorInterface; 然后在构造函数中,使用TranslatorInterface $ translator而不是Translator $ translator。

感谢@Thomas Mauduit-Blin