简体   繁体   English

将依赖项注入到自定义的日光浴室文档中

[英]Inject dependencies into a custom solarium document

I'm using NelmioSolariumBundle in a project to integrate . 我在一个项目中使用NelmioSolariumBundle来集成

My controller 我的控制器

$query = $this->client->createSelect(array(
    'documentclass' => 'MY\SolariumDocument'
));

In my custom documentclass , I have a field that store a reference of the category of the document retrived from . 在我的自定义documentclass ,我有一个字段,用于存储对从检索的文档类别的引用。 I need to replace that reference with the correspondent label. 我需要用相应的标签替换该引用。

That's why I thought of injecting doctrine.orm.entity_manager into my documentclass . 这就是为什么我想到将doctrine.orm.entity_manager注入到我的documentclass I turned it into a service and through a setter I injected the entity manager but it didn't work getRepository on non-object which makes sense because that transformation is made in the constructor. 我将其转换为服务,并通过设置器注入了实体管理器,但它对getRepository on non-object这是有意义的,因为该转换是在构造函数中进行的。

How do I transform attributes of my documentclass through doctrine.orm.entity_manager ? 如何通过doctrine.orm.entity_manager转换documentclass属性?

the best way is factor class which uses solr and the entity-manager. 最好的方法是使用solr和entity-manager的因子类。

  1. get your document from solr 从solr获取您的文档
  2. transform the fields you want 转换您想要的字段

You can try the solr-bundle . 您可以尝试solr-bundle It integrates solr-documents/indexing into doctrine. 它将solr-documents / indexing集成到理论中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM