为什么我的javascript文件找不到资产?

时间:2016-03-08 20:46:50

标签: javascript symfony assetic

我使用Twig作为我的模板,利用布局,我有一个javascript块

...
    {% block javascripts %}
        {% javascripts
            '@jquery'
            '@bootstrap_js' %}
        <script src="{{ asset_url }}"></script>
        {% endjavascripts %}
    {% endblock %}


</body>

在内容模板中,我有

{% block javascripts %}
    {{ parent() }}
    {% javascripts '@AppBundle/Resources/public/index/*' %}
    <script src="{{ asset_url }}"></script>
    {% endjavascripts %}
{% endblock %}

这是config.yml的资产部分

assetic:
debug:          true
use_controller: false
filters:
    cssrewrite: ~
assets:
    bootstrap_js:
        inputs:
            - %kernel.root_dir%/../vendor/twbs/bootstrap/dist/js/bootstrap.min.js
    bootstrap_css:
        inputs:
            - %kernel.root_dir%/../vendor/twbs/bootstrap/dist/css/bootstrap.css
            - %kernel.root_dir%/../vendor/twbs/bootstrap/dist/css/bootstrap-theme.css
        filters:
            [cssrewrite]
    bootstrap_glyphicons_ttf:
        inputs:
            - %kernel.root_dir%/../vendor/twbs/bootstrap/dist/fonts/glyphicons-halflings-regular.ttf
        output:
            "../fonts/glyphicons-halflings-regular.ttf"
    bootstrap_glyphicons_eot:
        inputs:
            - %kernel.root_dir%/../vendor/twbs/bootstrap/dist/fonts/glyphicons-halflings-regular.eot
        output:
            "../fonts/glyphicons-halflings-regular.eot"
    bootstrap_glyphicons_svg:
        inputs:
            - %kernel.root_dir%/../vendor/twbs/bootstrap/dist/fonts/glyphicons-halflings-regular.svg
        output:
            "../fonts/glyphicons-halflings-regular.svg"
    bootstrap_glyphicons_woff:
        inputs:
            - %kernel.root_dir%/../vendor/twbs/bootstrap/dist/fonts/glyphicons-halflings-regular.woff
        output:
            "../fonts/glyphicons-halflings-regular.woff"
    jquery:
        inputs:
            - %kernel.root_dir%/../vendor/components/jquery/jquery.min.js

@AppBundle/Resources/public/index/*下的文件外,其他所有工作正常。我为我的环境运行assetic:dump,一切顺利,但我在@AppBundle/Resources/public/index/*

的脚本元素下面继续获得404 HTML转储
<script src="/logbook/web/js/431d650.js">
    <!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8" />
    <title>An Error Occurred: Not Found</title>
</head>
<body>
    <h1>Oops! An Error Occurred</h1>
    <h2>The server returned a "404 Not Found".</h2>

    <div>
        Something is broken. Please let us know what you were doing when this error occurred.
        We will fix it as soon as possible. Sorry for any inconvenience caused.
    </div>
</body>
</html>
</script>
显然有些事情已经破裂,但我无法弄清楚是什么???

1 个答案:

答案 0 :(得分:0)

我在过去也曾遇到过使用资产问题的一些问题,并写下了我如何使用它的方法。如果您在转储资产之前尝试先执行以下命令,它可能对您有所帮助:

php app/console assets:install --symlink web