dpecb06062 2016-09-08 06:43
浏览 47

在service的标记定义中使用config.yml参数

I'd like to put a class name (which has been configured in app/config/config.yml by the user) in the tag definition of my Bundle's service configuration.

app/config/config.yml :

my:
    class_name: AppBundle\Entity\Product

My bundle's configuration : services.xml

<service id="my.entity_listener" class="My\EventListener\MyListener">
    <tag name="doctrine.orm.entity_listener" entity="%my.class_name%" event="preUpdate" />
</service>

Is that possible in any way ? All I can get is %my.class_name%. It isn't replaced in the tag definition. Although, my dependency injection is working as it replaces it well just above, in the same config file :

<service id="my.param_converter" class="My\ParamConverter\MyParamConverter">
    <tag name="request.param_converter" converter="user" priority="10" />
    <argument type="service" id="doctrine.orm.default_entity_manager" />
    <argument>%my.class_name%</argument> <!-- Replaced by AppBundle\Entity\Product -->
</service>
  • 写回答

2条回答 默认 最新

  • dpdyh86002 2016-09-08 08:15
    关注

    In my projects, if I want to add some custom parameters globally in config.yml I do something like this:

    parameters:
        my:
          - {class_name: "AppBundle\Entity\Product"}
    
    评论

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)