Symfony 无法为路由到样式表生成 URL [英] Symfony Unable to Generate a URL for Route to Stylesheet
问题描述
我在同一个文件夹中有两个 CSS 文件,具有相同的访问权限.在同一个 Twig 文件中进行测试时,一个 CSS 文件会生成该文件的 URL 并完美加载,但一个错误.
I have two CSS files in the same folder, with identical access rights. When testing in the same Twig file, one CSS file generates a URL to the file and loads perfectly and one gives an error.
模板渲染过程中抛出异常(无法为命名路由_assetic_a328b4c_0"生成 URL 作为这样的路线不存在.")在@GutensiteStream/Stream35163.html.twig在第 19 行.
An exception has been thrown during the rendering of a template ("Unable to generate a URL for the named route "_assetic_a328b4c_0" as such route does not exist.") in @GutensiteStream/Stream35163.html.twig at line 19.
服务器上的文件
ls -al /var/www/core/cms/src/Templates/GutensiteAdminBundle/Resources/public/css
-rw-rw-r-- 1 chadwick developer 17K Feb 7 14:00 dashboard.css
-rw-rw-r-- 1 chadwick developer 49K Feb 6 16:00 site.css
带有可加载 CSS 的模板
{% stylesheets '@TemplatesGutensiteAdminBundle/Resources/public/css/site.css' %}
<link rel="stylesheet" href="{{ asset_url }}">
{% endstylesheets %}
带有不加载 CSS 的模板
{% stylesheets '@TemplatesGutensiteAdminBundle/Resources/public/css/dashboard.css' %}
<link rel="stylesheet" href="{{ asset_url }}">
{% endstylesheets %}
直接链接到文件
<link rel="stylesheet" href="/gutensite/v/2/0/bundles/templatesgutensiteadmin/css/dashboard.css">
采取的步骤
我已经多次清除缓存,通过app/console cache:clear
和通过rm -rf app/cache/*
.我使用 php app/console assets:install --symlink/var/www/core/web/gutensite/v/2/0/
将公共文件符号链接到包,当然它们是可访问(如通过直接链接所示).
Steps Taken
I have already cleared cache multiple times, via app/console cache:clear
and via rm -rf app/cache/*
. I use php app/console assets:install --symlink /var/www/core/web/gutensite/v/2/0/
to symlink the public files to the bundles, and of course they are accessible (as demonstrated via the direct link).
assetic:
#don't use dynamic links to assets, use full production paths
use_controller: false
推荐答案
当我遇到这个错误时,解决方案很简单:
When I ran into this error, the solution was quite simple:
如有疑问:
bin/console cache:clear
Assetic 正在寻找一个不存在的缓存版本.这可能有多种原因,但 cache:clear
似乎应该是第一站.
Assetic is looked for a cached version which doesn't exist. This could be for any number of reasons, but cache:clear
seems like it should be the first stop.
这篇关于Symfony 无法为路由到样式表生成 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!