1

我会尽量保持简短,不想浪费你的时间。在开发环境中工作:

模板:

{% block javascripts %}
   {% javascripts '@SomeBundle/Resources/public/js/*' %}
      <script type="text/javascript" src="{{ asset_url }}"></script>
   {% endjavascripts %}

{% endblock %}

html输出:

<script type="text/javascript" src="/js/98b0881_part_1_fill_form.jquery_1.js"></script>                            
<script type="text/javascript" src="/js/98b0881_part_1_jquery-1.8.3.min_2.js"></script>

因此它会读取 Resources/public/js 目录的内容,并使用正确的名称创建正确数量的链接。但是,当我单击给定的 url 时,我得到 404 apache 响应:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
    <html><head>
        <title>404 Not Found</title>
    </head><body>
    <h1>Not Found</h1>
    <p>The requested URL /js/98b0881_part_1_jquery-1.8.3.min_2.js was not found on this server.</p>
    <hr>
    <address>Apache/2.2.22 (Ubuntu) Server at ipardon.loc Port 80</address>
</body></html>

这几乎意味着我的页面上没有 JS。我试过什么:

app/console assets:install web --no-dev
app/console assetic:dump --no-dev

将 config.yml 中的包名称添加到assetic.bundles[] 谷歌搜索(当然)

以前有人遇到过这样的事情吗?我有,并且通过不使用资产来“解决”它,但这次我想把它做好。有任何想法吗?

4

2 回答 2

5

如此处所述您可以使用

php app/console assetic:dump --watch

如果它们被更改,它将自动转储您的资产。

这篇文章也有关于该主题的信息

于 2013-06-26T08:04:23.270 回答
1

在生产中,您实际上只需要每次部署转储一次,这可以自动化(请参阅 Capifony)。

在开发中不要使用--no-dev参数,这只会使资产转储编译文件,忽略部分/js/98b0881_part_1_jquery-1.8.3.min_2.js

于 2013-05-18T18:03:09.143 回答