I am working with Symfony 2.8 and encounter the problem, that real files within the web/
dir cannot be found (HTTP Error 400
) when using the dev controller app_dev.php
:
web/
css/
base.css
base_base_1.css
images/
someFile.png
I am using a very simply CSS structure. The assets/images are only stored within web/images
and not copied/linked by Assetic
or something else. Thus the assets images are simply linked using a "direct" relative URL with the CSS files:
// AppBundle/Resources/styles/base.scss
.someClass {
background: url("../images/someFile.png") no-repeat 0 0;
}
// Page Template
{% stylesheets
'@AppBundle/Resources/styles/base.scss'
filter="scssphp"
output="css/base.css" %}
<link rel="stylesheet" href="{{ asset_url }}" type="text/css" />
{% endstylesheets %}
Depending on whether app_dev.php
is used or not, this results in using base.css
or base_base_1.css
:
// app_dev.php NOT uses
<link rel="stylesheet" href="/css/base.css" type="text/css" />
// app_dev.php used
<link rel="stylesheet" href="app_dev.php/css/base_base_1.css" type="text/css" />
No matter if app_dev.php
is used or not, in both .css files, the path to the image is the same: url("../images/someFile.png")
However when calling example.com/somepage
everything works fine, while calling or example.com/app_dev.php/somepage
I get an Error 404
:
URL: /app_dev.php/images/someFile.png
Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\NotFoundHttpException
When I test this manually the result is the same: example.com/app_dev.php/images/someFile.png
leads to an error, while example.com/images/someFile.png
loads without any problem.
What am I doing wrong?
I have created a test file web/test.php
which shows the same behavior: Calling in normal mode is no problem, calling in app_dev.php
produces 404. Is this normal behavior of dev-mode?
But why can I access the existing files base.css
and base_base_1.css
, no matter wether dev-mode is used or not?
What can I do, to access the assets in dev-mode?
you need to create css, js and images into the YourBundle/Resources/public/
And then, in version 2.8, you need create the link to web dir with the command.
app/console assets:install web --symlink
And in the template use:
asset('bundles/yourbundlename/css|js|images...')