doujunchi1238
doujunchi1238
2016-08-02 23:27
浏览 30
已采纳

Symfony 3无法找到我的.svg图标

I have recently installed symfony 3 on a fresh Ubuntu server, I was previously using WAMP to run my symfony website but now I have migrated.

Everything is up and running except on one of my pages I have some .svg icons to show the weather. These icons are getting a 404 error.

I have made sure they are in the correct location and I havent changed any of the html that links to them from the windows version which works fine.

They are located in web>icons>weather

My img tag <img src="icons/weather/{{ item.icon }}.svg" /> item.icon is using twig to grab from my weather rss feed.

That outputs GET http://192.168.0.53/icons/weather/cloud.svg 404 (Not Found) in inspect and I cannot access it by going to that url manually.

Is there a .htaccess problem which causes my images to not be located correctly?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dpjs2005
    dpjs2005 2016-08-06 14:03
    已采纳

    Alright, I found the answer.

    I had a thought (like the one in my comment) that Symfony might be looking for/use a folder named "icons" in the web folder in its own way.

    Whether this is the case or not I don't know but I moved the icons into a vendor folder. The address is now vendor/icons/weather/cloud.svg and IT WORKS!

    So I guess what we can learn from this is either its a stupid error from me which I still don't know about or you can't use a folder called "icons" in the web folder.

    Thanks for you help Alvin

    点赞 评论
  • dso0139
    dso0139 2016-08-02 23:35

    I'm not sure if something like this might work:

    <img src="{{ asset('icons/weather/'.{{ item.icon }}.'.svg') }}" />
    

    Can you try it! You might need to modify slightly.

    点赞 评论

相关推荐