简体   繁体   English

覆盖每个bundle symfony2中的parameters.yml

[英]Override parameters.yml in each bundle symfony2

I'm working on a complex Symfony project. 我正在从事一个复杂的Symfony项目。 In the project, we have a core bundle which uses the parameters.yml located in app/config. 在项目中,我们有一个核心包,它使用位于app / config中的parameters.yml。

Each other AppBundle will inherit this CoreBundle and will correspond to a website. 每个其他AppBundle都将继承此CoreBundle并将与一个网站相对应。

What I need is to have specific parameters in each bundle that will override the default parameters one: when I'll use a route that will bring me into a controller's bundle, the parameters of this specific bundle have to override all the other ones. 我需要的是在每个捆绑软件中都有特定的参数,这些参数将覆盖默认参数:当我使用将我带入控制器捆绑软件的路由时,此特定捆绑软件的参数必须覆盖所有其他参数。

I've tried the preprend method but it doesn't fit to this need. 我已经尝试过preprend方法,但它不适合这种需求。 It only allows me to create new parameters for this bundle, but not to override the other ones. 它只允许我为此包创建新参数,而不能覆盖其他参数。

I think you misunderstand the idea of bundles in Symfony. 我认为您误解了Symfony中捆绑软件的想法。 Bundle by design should be a reusable module, therefore the configuration placed inside a bundle is the default one. 设计上的捆绑软件应该是可重用的模块,因此捆绑软件中的配置是默认配置。 Then it is possible to override parameters (and not only!) in configuration in app folder. 然后可以覆盖app文件夹中的配置中的参数(而不仅仅是!)。

The basic idea is: 基本思想是:

Bundles don't use application. 捆绑包不使用应用程序。 Application uses bundles. 应用程序使用包。

So it's completely the opposite to what you expect it to be. 因此,这与您的预期完全相反。 Acutally it makes no sense to condition whole application configuration depending on current route since bundles can use one another. 从根本上说,根据当前路由来限制整个应用程序配置是没有意义的,因为捆绑包可以互相使用。 What if your currenct action will internally (without redirect) call another bundle's service or even controller? 如果您的当前动作将在内部(无重定向)调用另一个捆绑软件的服务甚至控制器,该怎么办?

Also it's worth mentioning that the app folder is the final folder for your application, therefore you can override in it not only bundle's configuration but also other things like services, view templates and so on. 另外值得一提的是, app文件夹是app最终文件夹,因此,您不仅可以在其中覆盖包的配置,而且还可以覆盖服务,视图模板等其他内容。

Edit: I forgot to suggest a solution for you :) 编辑:我忘了为您建议解决方案:)

Since you want to use custom parameters inside bundle, why do you need the default value in first place? 由于要在包中使用自定义参数,因此为什么首先需要默认值? Just create separate parameter namespace for each bundle that won't be overridden by application config. 只需为不会被应用程序配置覆盖的每个包创建单独的参数名称空间 Then use it only inside that bundle. 然后仅在该捆绑包内使用它。

Solution found thanks to dragoste's asking about separated kernels. 找到了解决方案,这是由于dragoste询问了分离的内核。

To solve my problem, I had to split the kernels : one for each website. 为了解决我的问题,我不得不拆分内核:每个网站一个。

Documentation can be found here : 文档可以在这里找到:

http://jolicode.com/blog/multiple-applications-with-symfony2 http://jolicode.com/blog/multiple-applications-with-symfony2

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

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