symfony – 找不到“GET imgglyphicons-halflings.png”的路线

symfony – 找不到“GET imgglyphicons-halflings.png”的路线,第1张

概述我有一个关于symfony2和bootstrap的问题.我不明白为什么我可以从环境“prod”加载图标图像,但不能从环境“dev”加载.在开发中,我收到此错误. 路线是“GET /img/glyphicons-halflings.png”. Image web / img / glyphicons-halflings.png是../../vendor/twitter/bootstrap/img/g 我有一个关于symfony2和bootstrap的问题.我不明白为什么我可以从环境“prod”加载图标图像,但不能从环境“dev”加载.在开发中,我收到此错误.

路线是“GET /img/glyphicons-halflings.png”.

Image web / img / glyphicons-halflings.png是../../vendor/twitter/bootstrap/img/glyphicons-halflings.png的符号链接

我得到这个错误

http://my.web.site/app_dev.PHP/img/glyphicons-halflings.png

并获得图像

http://my.web.site/img/glyphicons-halflings.png

UPDATE

我以这种方式包含bootstrap:

{% stylesheets '%kernel.root_dir%/../vendor/twitter/bootstrap/less/bootstrap.less' %}    <link rel="stylesheet" type="text/CSS" href="{{ asset_url }}" />{% endstylesheets %}

当我在prod使用时,这是有效的

<span ></span>

我有这个资产配置:

assetic:    deBUG:          %kernel.deBUG%    use_controller: false    bundles:        [ MyAwesomeBundle ]    filters:        lessPHP:            file: %kernel.root_dir%/../vendor/leafo/lessPHP/lessc.inc.PHP            apply_to: "\.less$"

我也试过创建我的收藏:

assetic:    assets:        senso:            inputs:                - '../img/glyphicons-halflings.png'            outputs:                - 'img/glyphicons-halflings.png'            filters:                - ?lessPHP

:dump create web / assetic / senso.png和web / assetic / senso_glyphicons-halflings.png但是,…如何使用senso * .png图像?

解决方法 config.yml

assetic:    use_controller: false    filters:         lessPHP:             file: "%kernel.root_dir%/../vendor/leafo/lessPHP/lessc.inc.PHP"    assets:           img_bootstrap_glyphicons_black:            inputs:                -  "%kernel.root_dir%/../vendor/twitter/bootstrap/img/glyphicons-halflings.png"            output: "img/glyphicons-halflings.png"        img_bootstrap_glyphicons_white:            inputs:                -  "%kernel.root_dir%/../vendor/twitter/bootstrap/img/glyphicons-halflings-white.png"        output: "img/glyphicons-halflings-white.png"        CSS_bootstrap:            inputs:                -  "%kernel.root_dir%/../vendor/twitter/bootstrap/less/bootstrap.less"            output: "CSS/bootstrap.CSS"            filters:                - lessPHP        Js_bootstrap:            inputs:                -  "%kernel.root_dir%/../vendor/twitter/bootstrap/Js/*.Js"            output: "Js/bootstrap.Js"

config_dev.yml

assetic:    use_controller: true

模板

{% stylesheets '@CSS_bootstrap' %}<link href="{{ asset_url }}" rel="stylesheet" type="text/CSS"/>{% endstylesheets %}{% JavaScripts '@Js_bootstrap' %}<script src="{{ asset_url }}" type="text/JavaScript"></script>{% endJavaScripts %}

在运行assetic之后:dump –no-deBUG一切运行完美无缺.

基本信息

使用的CSSrewrite过滤器,例如用于background-image:url(“..”)与@ Bundle语法不兼容.

{% stylesheets    '@AcmeYourBundle/Resources/public/CSS/your.CSS'    filter="CSSrewrite" %}

不起作用.

此外,像url(“../ img / image.png”)这样的来源在开发环境中会失败而没有CSSrewrite和assetic.use_controller:true – 可能的解决方法:使用url,如url(“/ img / image.png”)但不是使用子文件夹中的页面.

你应该记住……

<img src="img/image.png">

…将用于hostname / app_dev.PHP /以及除hostname /之外的所有其他路由.

解:

<img src="{{ asset('img/image.png') }}">

其他解决方案&提示

>当将img,CSS或Js包含到您的页面时,请始终使用twig的asset(),{%stylesheets%}或{%JavaScripts%}函数.
>在样式表中使用相对网址,即url(“../ img / image.png”)
>尝试在config_dev.yml中设置assetic.use_controller:false并转储您的资产……如here所述
>在config.yml中创建asset collections,然后转储您的资产 – 请参阅我的answer here.
>使用CSSembedded过滤器使用data-uris – 参考here将图像包含在CSS中
>将您的网络服务器配置为直接提供img / CSS / Js文件夹中的文件,而不是通过symfony进行路由
>使用app_dev.PHP作为目录索引,为dev环境使用不同的主机名(即project.dev),从而生成没有/app_dev.PHP/的url

你可以在this question的答案中找到关于这个主题的一些很好的信息.

我个人工作流程:

>本地通配符DNS服务器引入自动生成的url,如project.dev,project.prod,…(没有/app_dev.PHP/问题)
>在config.yml中创建asset collections(更清晰的模板,更多地控制资产)
> guard/grunt taskrunners而不是assetic:dump –watch(改变时重新转储,但测试和优化)
> source-maps和Chrome-devtools而不是资产的资产:dump –deBUG(查看组合文件的真实源文件,less,sass,coffeescript,…)> tincr(直接从devtools保存)和livereload(立即查看更改)

总结

以上是内存溢出为你收集整理的symfony – 找不到“GET /img/glyphicons-halflings.png”的路线全部内容,希望文章能够帮你解决symfony – 找不到“GET /img/glyphicons-halflings.png”的路线所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1048465.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存