"gedmo.listener.translatable" 服务或别名在编译容器时已被删除或内联
The "gedmo.listener.translatable" service or alias has been removed or inlined when the container was compiled
我正在使用 PHP Symfony 4.4,在 SearchController 中的操作中,我得到了这部分代码:
$translatableListener = $this->get('gedmo.listener.translatable');
$carsRepository = $this->getCarsTranslationsRepository();
$locale = $translatableListener->getListenerLocale();
当我点击搜索按钮时,它显示了这个问题:
The "gedmo.listener.translatable" service or alias has been removed or inlined when the container was compiled. You should either make it public or stop using the container directly and use dependency injection instead.
我试图通过在 services.yml
中添加这部分代码来解决这个问题
gedmo.listener.translatable:
class: Gedmo\Translatable\TranslatableListener
public: true
tags:
- { name: doctrine.event_subscriber, connection: default }
然而这仍然不起作用,有什么帮助吗?
解决方案:
$translationListener = new Gedmo\Translatable\TranslatableListener();
我正在使用 PHP Symfony 4.4,在 SearchController 中的操作中,我得到了这部分代码:
$translatableListener = $this->get('gedmo.listener.translatable');
$carsRepository = $this->getCarsTranslationsRepository();
$locale = $translatableListener->getListenerLocale();
当我点击搜索按钮时,它显示了这个问题:
The "gedmo.listener.translatable" service or alias has been removed or inlined when the container was compiled. You should either make it public or stop using the container directly and use dependency injection instead.
我试图通过在 services.yml
中添加这部分代码来解决这个问题gedmo.listener.translatable:
class: Gedmo\Translatable\TranslatableListener
public: true
tags:
- { name: doctrine.event_subscriber, connection: default }
然而这仍然不起作用,有什么帮助吗?
解决方案:
$translationListener = new Gedmo\Translatable\TranslatableListener();