Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php “我该如何解决?”;将myBundle添加到asseticBundle配置中;symfony2异常?_Php_Symfony_Twig - Fatal编程技术网

Php “我该如何解决?”;将myBundle添加到asseticBundle配置中;symfony2异常?

Php “我该如何解决?”;将myBundle添加到asseticBundle配置中;symfony2异常?,php,symfony,twig,Php,Symfony,Twig,当我试图使用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:ind

当我试图使用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".
我的
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>

如何修复此问题?

您需要将您的捆绑包添加到捆绑包中:[]app/config/config.yml文件(symfony 2.1)中的assetic:section行。

是的,我尝试过,它为我解决了问题。对于一开始不知道如何添加的人(如我),只需:

  • 编辑app/config/config.yml
  • 然后转到
    assetic:
  • 在assetic下:转到
    bundles:[]
  • bundle:[]
    //中键入您的bundle名称
  • 例如,如果您的bundle是
    Acme\DemoBundle
    ,请执行以下操作

    assetic:
       bundles: [ AcmeDemoBundle ]
    

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

    如果您希望assetic在默认情况下包括您的bundle,您可以在
    bundles:[]

    例:


    有时你需要在飞行中做出决定,然后你可以使用

    例如:


    检查这个问题和两个建议的解决方案:如果你真的选择了这个问题的答案,那就太好了。评论捆绑包有什么副作用吗?我想不出来。它只会使assetic包含项目中的所有捆绑包。也许它会减慢你的应用程序的速度,但就我个人而言,我从未注意到速度上的任何差异。如果需要,其他捆绑包应该用逗号分隔。我使用的是symfony2.3,我将捆绑包添加到阵列中,但我仍然有相同的例外。即使我对bundle进行注释,也会收到相同的异常消息。我该怎么办?如果您要迁移到prod,并且遇到了这个问题,请不要忘记清理缓存并转储资产:“php应用程序/控制台缓存:clear--env=prod--no debug”和“php应用程序/控制台assetic:dump--env=prod--no debug”@Dev DOS您找到解决方案了吗?如果您使用Bundle继承扩展另一个Bundle,这一点尤其有用。
    
    assetic:
       bundles: [ AcmeDemoBundle ]
    
    assetic:
        debug:          "%kernel.debug%"
        use_controller: false
        #bundles:        [ ]
        #java: /usr/bin/java
    
    <?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);
    
            /* ... */
        }
    }