Symfony 2将应用程序拆分为更多捆绑包 [英] Symfony 2 split application to more bundles

查看:123
本文介绍了Symfony 2将应用程序拆分为更多捆绑包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将我的应用程序分成两个捆绑包。



后端捆绑包将类似于CMS admin(可重用于其他项目)和前端



我将整个后端应用程序(包括控制器,模板和模型)移到了新的捆绑软件中,但是我的项目所依赖的第三方捆绑软件存在问题。 / p>

例如AsseticBundle。当我将资产配置添加到BackendBundle / config.yml时,我收到异常。

 没有扩展能够加载以下配置 asstic 

是否有一些不错的教程,展示了如何将应用程序拆分为两个具有一个配置的协作包,以及都依赖于第三方库吗?



感谢任何建议。

解决方案

如果我对您的理解正确,则您正在尝试将第三方捆绑包配置添加到自己的捆绑包配置中。



这只能在<$ c $中实现c> app / config / config.yml ,默认情况下由Symfony加载。这是Symfony唯一的外观。



您可以做的是通过自己的扩展名进行配置。可以放在您的捆绑包中:

 使用Symfony\组件\DependencyInjection\Extension\PrependExtensionInterface; 

类BackendBundleExtension扩展了扩展实现PrependExtensionInterface
{
公共功能prepend(ContainerBuilder $ container)
{
$ container-> prependExtensionConfig('assetic' ,array(
'key'=>'value'
));
}
}

如果足够的话,请告诉我。


I want to split my application to two bundles.

Back-end bundle which will be something like CMS admin(reusable to another projects), and Front-end bundle.

I moved whole backend application including controllers, templates and model to new bundle, but I have a problem with 3rd-party bundles on which my project is dependent.

For example AsseticBundle. When I add assetic configuration to BackendBundle/config.yml i recieve a exception.

There is no extension able to load the configuration for "assetic"

Is there some good tutorial showing how to split application to two cooperating bundles with one config and both dependent to 3rd-party libraries?

Thanks for any advice.

解决方案

If I understand you correctly, you're trying to add 3rd party bundle configuration to your own bundle config.

This can be achieved only in app/config/config.yml, which is loaded by default by Symfony. It's the only place where Symfony looks.

What you can do, is prepend configuration via own extension. That can be placed in your bundle:

use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;

class BackendBundleExtension extends Extension implements PrependExtensionInterface
{
    public function prepend(ContainerBuilder $container)
    {
        $container->prependExtensionConfig('assetic', array(
            'key' => 'value'
        ));
    }
}

Let me know, if this is sufficient explanation.

这篇关于Symfony 2将应用程序拆分为更多捆绑包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆