We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Unable to load static css file

Hi,

I'm not sure there's bb tags for code etc.. so pardon in advance.

My html template:

{# app/views/templates/main.volt #}

<!DOCTYPE html>
<html>
<head>
    <title>{% block title %}{% endblock %}</title>
    <meta charset="utf8">
    <link rel="stylesheet" href="{{ static_url( "public/css/main.css" ) }}">
</head>
<body>
    <div id="content">
        {% block content %}{% endblock %}
    </div>
</body>
</html>

The output is:

<!DOCTYPE html>
<html>
<head>
    <title>My Index Page</title>
    <meta charset="utf8">
    <link rel="stylesheet" href="/catechize/public/css/main.css">
</head>
<body>
    <div id="content">

<h1>Index</h1>

    </div>
</body>
</html>

When I try to load that CSS file, which physically exists, it tries to load a Controller: CatechizeController handler class cannot be loaded

Though my .htaccess in public folder skips real files:

AddDefaultCharset UTF-8

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
</IfModule>

Thanks for any help!



58.4k
Accepted
answer

@Boris Lapouga You try replace <link rel="stylesheet" href="{{ static_url( "public/css/main.css" ) }}"> into {{ stylesheet_link('css/main.css') }}

It doesn't matter.

Even when I try it like that: https://www.catechize.com/catechize/public/css/main.css it tries to load controller.

edited Mar '14

@Boris, pleas try first to call your CSS with plain html, to check if it will work.

in app/views/templates/main.volt:

<link rel="stylesheet" href="css/main.css">

or

<link rel="stylesheet" href="../css/main.css">

{{ stylesheet_link('css/main.css') }} should print out your base URI + css/main.css. Did you set up a base URI in your index.php (can you show your code)?



15.4k

do you set base uri in url service ?