php 如何修复“将 myBundle 添加到 asseticBundle 配置”symfony2 异常?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12222900/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 03:04:02  来源:igfitidea点击:

How do I fix "Add myBundle to the asseticBundle config" symfony2 exception?

phpsymfonytwig

提问by Vimal Basdeo

When I am trying to use the TWIG {% javascript %}tag to link to my .jsfile it return me with the following exception :

当我尝试使用 TWIG{% javascript %}标签链接到我的.js文件时,它返回给我以下异常:

An exception has been thrown during the compilation of a template ("You must add CompetitiongameBundle to the assetic.bundle config to use the {% javascripts %} tag in CompetitiongameBundle:game:index.html.twig.") in "CompetitiongameBundle:game:index.html.twig".

My index.html.twiglooks like :

我的index.html.twig样子:

{% javascripts 'CompetitiongameBundle/Resources/views/public/js/*'%}
    <script type="text/javascript" src="{{ asset_url }}" ></script>
{% endjavascripts %}
Hello {{ name }}!

<a href='{{ nexturl }}' >Login</a>

My Bundle is already present in the config file when I do :

当我执行以下操作时,我的 Bundle 已存在于配置文件中:

php app/console config:dump-reference assetic

How can I fix this ?

我怎样才能解决这个问题 ?

回答by Shabbir Reshamwala

Yes I tried and it solved the issue for me. For someone (like me) who doesn't know initially how to add then just:

是的,我试过了,它为我解决了这个问题。对于最初不知道如何添加的人(如我),只需:

  1. edit app/config/config.yml
  2. then go to assetic:
  3. under assetic: go to bundles: []
  4. and in bundles: []//type your bundle name
  1. 编辑 app/config/config.yml
  2. 然后去 assetic:
  3. 在资产下:转到 bundles: []
  4. 并在bundles: []// 输入您的捆绑包名称

for instance if your bundle is Acme\DemoBundle, then do the following

例如,如果您的捆绑包是Acme\DemoBundle,则执行以下操作

assetic:
   bundles: [ AcmeDemoBundle ]

No quotes around AcmeDemoBundle. That's it. (Symfony2)

周围没有引号AcmeDemoBundle。就是这样。(Symfony2)

回答by Tivie

If you want assetic to include your bundles by default, you can comment (with #) the line bundles: []

如果您希望资产默认包含您的捆绑包,您可以评论(用#)该行 bundles: []

ex:

前任:

assetic:
    debug:          "%kernel.debug%"
    use_controller: false
    #bundles:        [ ]
    #java: /usr/bin/java

回答by Максим Шатов

Sometimes you need to make decisions on the fly, then you can use use DependencyInjection.

有时您需要即时做出决定,然后您可以使用DependencyInjection

For example to loads and manages configuration:

例如加载和管理配置

<?php

namespace You\ExampeBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;

/* ... */

class YouExampeExtension extends Extension
{

    /* ... */

    public function load(array $configs, ContainerBuilder $container)
    {
        /* ... */

        $aAsseticBundle = $container->getParameter('assetic.bundles');
        $aAsseticBundle[] = 'YouExampeBundle';
        $aAsseticBundle[] = 'AnotheBundle';
        $container->setParameter('assetic.bundles', $aAsseticBundle);

        /* ... */
    }
}

You can use more complex logic to manipulate the configuration(in reasonable limits)

您可以使用更复杂的逻辑来操作配置(在合理范围内)

回答by user1041503

You need to add your bundle to bundle: [] row of assetic: section in app/config/config.yml file (symfony 2.1)

你需要将你的 bundle 添加到 bundle: [] row of assetic: app/config/config.yml 文件中的部分 (symfony 2.1)