我正在尝试使用JMSSerializerBundle,但运行app/console container:debug | grep jms_serializer
后未列出该服务
$ app/console container:debug | grep jms_serializer
jms_serializer.json_deserialization_visitor container JMS\SerializerBundle\Serializer\JsonDeserializationVisit
jms_serializer.json_serialization_visitor container JMS\SerializerBundle\Serializer\JsonSerializationVisitor
jms_serializer.metadata.lazy_loading_driver container Metadata\Driver\LazyLoadingDriver
jms_serializer.metadata_driver container Metadata\Driver\DriverChain
jms_serializer.naming_strategy container JMS\SerializerBundle\Serializer\Naming\CacheNamingStrate
jms_serializer.xml_deserialization_visitor container JMS\SerializerBundle\Serializer\XmlDeserializationVisito
jms_serializer.xml_serialization_visitor container JMS\SerializerBundle\Serializer\XmlSerializationVisitor
jms_serializer.yaml_serialization_visitor container JMS\SerializerBundle\Serializer\YamlSerializationVisitor
安装后
composer require jms/serializer-bundle
并配置
// in AppKernel::registerBundles()
$bundles = array(
// ...
new JMS\SerializerBundle\JMSSerializerBundle($this),
// ...
);
如果你在某个地方使用
$this->get('jms_serializer')
我收到错误You have requested a non-existent service "jms_serializer".
我如何解决这个问题?
答案 0 :(得分:3)
服务的名称是序列化程序。你应该使用以下内容。
$this->get('serializer');
答案 1 :(得分:0)
已安装捆绑软件,但没有在bundles.php中自动启用它。必须手动启用它。
启用JMSSerializerBundle:
JMS\SerializerBundle\JMSSerializerBundle::class => ['all' => true],
访问服务:
$serializer = $this->container->get('jms_serializer');
Symfony 4.4