【问题标题】:Assetic not creating combined linksAssetic 未创建组合链接
【发布时间】:2012-10-27 00:39:34
【问题描述】:

尝试让 Assetic 在呈现的网页中生成组合链接时遇到了一些问题。文件本身生成良好,但在生产环境的网页中,我继续看到单独的文件 URL(在生产中不起作用,因为那些未组合的文件不可用)。

在模板中,我有:

{% stylesheets
    '@TBundle/Resources/public/css/bootstrap/bootstrap.css'
    '@TBundle/Resources/public/css/bootstrap/bootstrap-responsive.css'

    '@TBundle/Resources/public/css/jquery-selectbox/jquery.selectBox.css'
%}
    <link href="{{ asset_url }}" rel="stylesheet" media="screen" />
{% endstylesheets %}

在生产中,这仍然呈现为:

<link href="/css/2f787d0_bootstrap_1.css" rel="stylesheet" media="screen" />
<link href="/css/2f787d0_bootstrap-responsive_2.css" rel="stylesheet" media="screen" />
<link href="/css/2f787d0_jquery.selectBox_3.css" rel="stylesheet" media="screen" />

尽管如此,当我调用 php app/console assetic:dump --env=prod 时,我得到:

11:13:43 [dir+] /var/www/tbundle/app/../web/css
11:13:43 [file+] /var/www/tbundle/app/../web/css/2f787d0.css

我正在使用 Symfony2 的默认 Assetic 设置。有什么想法可能导致这种情况吗?

【问题讨论】:

  • 是的。在我运行php app/console cache:clear --env=prod 命令之后,甚至运行rm -rf app/cache/* 以确保。

标签: symfony assetic


【解决方案1】:

我遇到了同样的问题,对我来说,问题出在我的 app.php 文件中。我正在按如下方式加载内核:

$kernel = new AppKernel('prod', true);

似乎这会导致函数无法在调试模式下运行并合并资产。当我将第二个参数更改为 false 时,资产在生产中成功组合,而在开发中保持未组合:

$kernel = new AppKernel('prod', false);

此外,您可以将 combine=true 作为参数传递,以明确请求合并资产,以测试此功能是否正常工作。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2017-06-10
  • 1970-01-01
  • 1970-01-01
  • 2015-11-24
  • 1970-01-01
  • 2015-06-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多