Image resources with Phalcon

十年热恋 提交于 2019-12-12 05:39:23

问题


I have the following code in my stylesheet:

body
{
    margin: 1cm 3cm 1cm;
    background-image:url("bg.png");
    background-position:center top;
    background-repeat:no-repeat;
}

But the background isn't found on the server. I have tested this code with just a basic html page and it does work, there must be something that isn't allowing it within the Phalcon framework.

Possibly the file location of the image? I have it in the same folder as the html file.


回答1:


Yes, I believe that the location of your file is "changing", I mean, when you access a page in your Phalcon application, all your server side includes will take as the current directory the path of your main bootstrap file (the main index.php file path), and for client side the browser will always think that the action executed (like www.myapp.com/users/login-form/) is actually a existent directory structure on your server (so the browser will try the load your background in www.myapp.com/users/login-form/bg.png).

That's why Phalcon offers many ways to deliver html assets to solve not only this problem but also make your application future proof (what if you need to move all your images, CSS and JS to a CDN server?), and here it is:

You could either use an assets manager(more advanced) or simply a view helper which can produce all assets URLs needed based on your url service configurations. Your application should have a valid URLs configuration by setting the desired base URI (for URLs that leads to Phalcon controllers) and your desired static URI (for URLs that leads to CSS files, images, etc), more info about this can be found here.



来源:https://stackoverflow.com/questions/24261546/image-resources-with-phalcon

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!