2017-05-26 45 views
0

我想基于这些页面向所有教义表添加前缀: docs.doctrine-project.org/projects/doctrine-orm/en/latest/cookbook/sql -table-prefixes.html和 stackoverflow.com/questions/7504073/how-to-setup-table-prefix-in-symfony2Symfony依赖注入修改服务参数

我也使用依赖注入来使用前缀定义的配置。 symfony.com/doc/current/service_container/definitions.html和symfony.com/doc/current/bundles/configuration.html

不幸的是我不能使用配置中定义的值作为前缀表。 但是,当我手动更改服务定义中的参数值时,它正在工作。

我的项目在这里举行:https://github.com/GrenobleSwing/API

查看文件:

  • 的src/GS/ApiBundle /资源/配置/ services.yml
  • 的src/GS/ApiBundle/EventSubscriber/TablePrefixSubscriber。 PHP
  • SRC/GS/ApiBundle/DependencyInjection /的configuration.php
  • SRC/GS/ApiBundle/DependencyInjection/GSApiExtension.php

在此先感谢您的帮助。

朱利安

+0

认为你错过了 'gs_api'这里的根名:https://github.com/GrenobleSwing/API/blob/master/src/GS/ApiBundle/DependencyInjection/GSApiExtension.php#L29。如果不是,'$ config'中有什么? –

+0

嗨,$ config包含配置。 var_dump($ config ['doctrine_table_prefix'])给出了前缀的期望值。 –

+0

此外,当我尝试在依赖注入($ def-> replaceArgument(0,'something_');)中硬编码前缀时,它不起作用。 –

回答

0

我克隆你的资料库,运行应用程序在容器中,发现了什么问题。

删除that line

为什么?

现在它加载相同的配置两次,并且配置中加载的配置被用于为Doctrine注册事件订阅者。所以您在GSApiExtension内的修改被省略了。

由我自己检查,它现在有效。

+0

谢谢,我永远不会找到这一个。 –