0

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.

cvsguimaraes
  • 12,910
  • 9
  • 49
  • 73
Josh Boiskin
  • 69
  • 1
  • 10

1 Answers1

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.

cvsguimaraes
  • 12,910
  • 9
  • 49
  • 73