Php Twitter引导图标字体';在Symfony2上的prod中使用assetic时未找到

Php Twitter引导图标字体';在Symfony2上的prod中使用assetic时未找到,php,twitter-bootstrap,symfony,assetic,Php,Twitter Bootstrap,Symfony,Assetic,我已经读了很多关于这个的帖子,但是我的项目没有做到这一点 所以基本上我有一个Symfony2项目,其中包括twitter引导(v3)。在开发模式下,一切都很好,但当我在prod模式下尝试时,我得到了一个错误,即无法找到twitter引导字体: Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:8080/Symfony/css/fonts/glyphicon

我已经读了很多关于这个的帖子,但是我的项目没有做到这一点

所以基本上我有一个Symfony2项目,其中包括twitter引导(v3)。在开发模式下,一切都很好,但当我在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
这是正常的,因为我在Symfony中没有css/文件夹/

以下是项目的结构:

app/
src/
vendor/
web/
   css/
      compiled/
   fonts/
   js/
细枝文件:

{% 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 %}
我已经签入bootstrap.min.css(在web/css/compiled中)文件(prod和dev),它们的字体路径相同。类似于(../../../fonts/fontName.ext)

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

有没有办法解决这个问题


我将不胜感激。

您不必在
Symfony/
路径下搜索它们,事实上Symfony2 webfolder是
web/
,所以url是相对于
web/
文件夹的

顺便说一句,您必须使用以下命令

php app/console assets:install
如果希望有符号链接,还可以将
--symlink
参数添加到命令中

那么资产:安装和资产:转储之间有什么区别呢?
assets:install
将符号链接或复制所需资源到“公共web文件夹”


assetic:dump
只会将所有js合并成一个

可能您应该尝试保持引导文件夹结构不变(例如使用bower下载)。顺便说一下,CSSRewite过滤器将解析您的css文件以反映字体的位置

如果使用“cssrerewrite”过滤器,它会将字体文件的路径(到其原始源)重写为前面提到的Maxoo

您可以通过以下方式为字体文件添加assetic路径(因此它们被复制到
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
然后打电话

php app/console assetic:dump --env=prod
将文件导出到web文件夹中的字体目录

希望这有帮助

正确的解决方案:

  • 安装Nodejs,设置symfony2配置文件,它会自动将您选择的cssrewite过滤器编译成CSS。这将解决这些错误

  • 我的config.yml和config_dev.yml看起来只是一个assetic部分-请非常小心路径语法,否则会出现以下错误“运行时发生错误:……错误:找不到模块‘less’”。许多人都会遇到这3条错误消息,请用谷歌搜索此字符串来查找“运行时出错:错误:找不到模块'less'”

资产:

debug: '%kernel.debug%'
use_controller:
       enabled: '%kernel.debug%'
       profiler: true
filters:
    cssrewrite: ~
    ###is for linux path i am on windows for dev and linux for prod
    less:
        ###node: /usr/bin/nodejs
        ###node_paths: [/usr/lib/nodejs]
        node: "C:\\Program Files (x86)\\nodejs\\node.exe"
        node_paths: ["C:\\Users\\John\\AppData\\Roaming\\npm\\node_modules"]
        apply_to: "\.less$"
  • 不要忘记安装“npm安装-g less”

  • 在我的特定情况下:当执行“php应用程序/控制台断言:转储”时,我会遇到相同的错误。这是因为我的Windows开发web服务器的设置如下:web根目录为“C:\xampp\htdocs\”,项目类似于“C:\xampp\htdocs\phantom”\“和assetic:dump将glyphicons-halflings-regular.ttf、glyphicons-halflings-regular.woff和glyphicons-halflings-regular.woff2放在“C:\xampp\htdocs\phantom\web\fonts”中。然而,当加载页面时,它看起来是“”,如您所见,这是我的开发设置的问题。因此,我将文件夹字体“C:\xampp\htdocs\phantom\web\fonts”复制到web根目录“C:\xampp\htdocs\”,解决了这个问题

  • 在服务器web根目录为“C:\xampp\htdocs\phantom\web\”的生产环境中不会发生这种情况。我在生产服务器上进行了测试,无需手动将fonts文件夹复制到webroot

  • 此外,在项目目录“php app/console assetic:dump”中运行相同的命令时,您将得到类似“FileError:”../bootstrap/less/bootstrap.less“未找到”这样的错误。try-../bootstrap/less/bootstrap.less,C:\xampp\htdocs\phantom\vendor\mopa\bootstrap bundle\mopa\bundle\bootstrap bundle\bootstrap\Resources\public\bootstrap”出于同样的原因,bootstrap是由“C:\xampp\htdocs\phantom\web\bootstrap”中的“php应用程序/控制台资产:安装”安装的,这不是正确的webroot目录,所以为了解决开发中的同一临时问题,我只需将目录“C:\xampp\htdocs\phantom\web\bootstrap”复制到解决问题的“C:\xampp\htdocs\bootstrap”。再次运行您的命令,它将很好、干净地编译为css


能否尝试将
字体
目录移动到
css
目录中?我已经尝试过了,但没有成功。您是否尝试删除“output”属性?(为了排除一些相对路径问题)嗨,谢谢你的回答。不幸的是,它不起作用。正如我刚才所说,我的最后一个css文件(main.css)是在web/css/compiled中,字体在web/fonts中,但是css文件中字体的url是类似smthg的(../../../../fonts/file.ext)@kiimsc:您收到任何错误吗?(请参阅我的更新,我已删除--env=prod)我在执行这些命令时没有任何错误,只是在转到webpage@kimimsc:您是否按照我的回答中现在的方式运行命令?您应该会收到一些来自CLIYes的消息,只是一些基本消息,说明它安装了什么以及安装在何处资产它确实有帮助。。。事实上,这是迄今为止唯一真正的解决方案,与我在其他地方找到的任何其他(糟糕的)解决方案相比,它要好得多。我不得不说,assetic对这一点非常不利,我希望有一天能纠正这个奇怪的错误(是的,这是一个错误)/只需添加以下内容:如果在dev env中工作,那么如果filter='cssrerewrite'在这里则不起作用。我需要删除它才能使这个好的解决方案正常工作。看起来您忘记了示例;)。
debug: '%kernel.debug%'
use_controller:
       enabled: '%kernel.debug%'
       profiler: true
filters:
    cssrewrite: ~
    ###is for linux path i am on windows for dev and linux for prod
    less:
        ###node: /usr/bin/nodejs
        ###node_paths: [/usr/lib/nodejs]
        node: "C:\\Program Files (x86)\\nodejs\\node.exe"
        node_paths: ["C:\\Users\\John\\AppData\\Roaming\\npm\\node_modules"]
        apply_to: "\.less$"