We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Css is not loaded -- wrong path


I've got a problem and I'm not able to find the mistake -- of course as I write here ^^ So I hope you can help me find my mistake.

I created a new basic Phalcon app - using namespaces, like my previous one. I copied most of the basic set up code from the old one.

But now my css and js files are not loaded, because Phalcon is adding an additional basic path into the URL.

So when I'm doing something like this: {{ stylesheet_link('css/bootstrap.min.css') }} The code in the rendered file looks like this: <link rel="stylesheet" type="text/css" href="slipbox/css/bootstrap.min.css" />

This does not work, because it tries to parse the URL that looks like this: "https://localhost/slipbox/slipbox/css/bootstrap.min.css" Which is obviously wrong.

When I do something like this: $headerCollection = $this->assets->collection('header'); $headerCollection->setPrefix('https://localhost/slipbox/public/'); $headerCollection->addCss('css/bootstrap.min.css'); it works!

But I don't want to use collections.

Has anyone an idea where I could fix the problem centrally? Where does this second 'slipbox' come from? I'm only setting a basicUri at the beginnning. Everything else is also working. So I'v got no clue.

Thanks a lot Aljoscha

the problem is in the basicUri. Other way use {{ stylesheet_link('https://example.com/css/bootstrap.min.css', false) }} like an externar assets

Good luck

Hi Emilio,

thanks for your answer. But that is the problem. I do not see the mistake.

This are the lines where I set the baseUri: $di->set('url', function () use ($config) { $url = new UrlResolver(); $url->setBaseUri($config->application->baseUri); return $url; }, true);

This is the value of $config->application->baseUri (with var_dump): 'slipbox'

This are the values, when I'm dumping $this->url in an index.volt: protected '_baseUri' => string 'slipbox' (length=7) protected '_staticBaseUri' => string 'slipbox' (length=7)

I never set a value for staticBaseUri ... I only set up once the $di = new FactoryDefault(). That is why I'm stuck at the moment.

Best, Aljoscha