在Symfony2上的prod中使用assetic时,找不到Twitter Bootstrap glyphicons字体

Mou*_*heg 4 php symfony twitter-bootstrap assetic

我已经阅读了很多关于这个的帖子,但是无法让这个用于我的项目.

所以基本上我有一个包含twitter bootstrap(v3)的Symfony2项目.在开发模式下,每件事都运行正常但是当我在prod模式下尝试它时,我得到错误,说无法找到twitter引导字体:

Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:8080/Symfony/css/fonts/glyphicons-halflings-regular.woff   
Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:8080/Symfony/css/fonts/glyphicons-halflings-regular.ttf  
Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:8080/Symfony/css/fonts/glyphicons-halflings-regular.svg#glyphicons_halflingsregular
Run Code Online (Sandbox Code Playgroud)

这是正常的原因我在Symfony中没有css /文件夹/

以下是项目的结构:

app/
src/
vendor/
web/
   css/
      compiled/
   fonts/
   js/
Run Code Online (Sandbox Code Playgroud)

树枝文件:

{% block stylesheets %}
    {% stylesheets output="css/compiled/main.css" filter='cssrewrite'
        'css/bootstrap.min.css'
        'css/general.css'
        'css/navigation.css'
    %}
        <link rel="stylesheet" href="{{ asset_url }}" />
    {% endstylesheets %}
{% endblock %}
Run Code Online (Sandbox Code Playgroud)

我用了:

php app/console assetic:dump --env=prod
Run Code Online (Sandbox Code Playgroud)

我已经检查了bootstrap.min.css(在web/css/compiled中)文件(prod和dev),它们都有相同的字体路径.像(../../../fonts/fontName.ext)这样的东西.

如果我们查看路径它不应该在开发模式或prod模式下工作,因为路径将字体/文件放在web目录之外.然而,它在开发模式下工作.

有关如何解决此问题的任何想法?

我会很高兴.

小智 12

如果你使用"cssrewrite"过滤器,它会重写字体文件的路径(到它们的原始来源),正如Maxoo已经说过的那样.

您可以按以下方式为字体文件添加资产路径(因此将它们复制到css/fonts/文件夹,css文件将使用原始../fonts/路径找到它们)

我使用了以下解决方案:

config.yml:

assetic:
    debug:          %kernel.debug%
    use_controller: false
    assets:
        bootstrap_fonts_woff:
            inputs:
                - 'original/path/to/bootstrap/fonts/glyphicons-halflings-regular.woff'
            output: fonts/glyphicons-halflings-regular.woff
        bootstrap_fonts_ttf:            
            inputs:
                - 'original/path/to/bootstrap/fonts/glyphicons-halflings-regular.ttf'
            output: fonts/glyphicons-halflings-regular.ttf
        bootstrap_fonts_svg:
            inputs:
                - 'original/path/to/bootstrap/fonts/glyphicons-halflings-regular.svg'
            output: fonts/glyphicons-halflings-regular.svg
        bootstrap_fonts_eot:
            inputs:
                - 'original/path/to/bootstrap/fonts/glyphicons-halflings-regular.eot'
            output: fonts/glyphicons-halflings-regular.eot
Run Code Online (Sandbox Code Playgroud)

然后打电话

php app/console assetic:dump --env=prod
Run Code Online (Sandbox Code Playgroud)

应该将文件导出到web文件夹中的fonts-directory.

希望这可以帮助!