我正在尝试建立一个我正在共享托管上工作的网站,一切正常,但 FontAwesome 图标,因为 Symfony 找不到它们应该在的位置。我按照以下步骤将网站移动到生产共享托管:
- 由于 SH 不允许符号链接,因此将资产发布为硬拷贝,因此我运行此命令
assets:install
- 通过运行以下命令来发布由 Assetic 处理的资产:
assetic:dump
(开发)和assetic:dump --env=prod
(prod)
但它不起作用,因为我一直在 Firebug 中收到此错误:
"NetworkError: 404 Not Found - http://tanane.com/bundles/backend/img/mybg.png"
"NetworkError: 404 Not Found - http://tanane.com/bundles/backend/fonts/fontawesome-webfont.woff?v=4.1.0"
"NetworkError: 404 Not Found - http://tanane.com/bundles/backend/fonts/fontawesome-webfont.ttf?v=4.1.0"
在本地主机上,按照相同的步骤一切正常,所以我不知道是权限问题还是其他问题。
这就是我定义资产的方式base.html.twig
:
{% block stylesheets %}
{% stylesheets
'bundles/template/css/bootstrap.min.css'
'bundles/template/css/bootstrap-theme.min.css'
'bundles/template/css/font-awesome.min.css'
'bundles/template/css/select2.css'
'bundles/template/css/select2-bootstrap.css'
'bundles/template/css/bootstrapValidator.min.css'
'bundles/template/css/datepicker.css'
'bundles/template/css/datepicker3.css'
'bundles/template/css/tanane.css'
filter='cssrewrite'
%}
<link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}
{% endblock %}
我做了一项研究,发现了很多围绕这个问题的主题,例如this one我还发现这个有趣的但我对第二个有疑问。
有人可以帮我解决这个问题吗?我被困住了
安装 SpBowerBundle + FkrCssURLRewriteBundle
我已经安装并配置了两个捆绑包,但即使在这种情况下,我仍然遇到图像问题,仅在 Select2 库中。
这是bower.json
文件内容:
{
"name": "TemplateBundle",
"dependencies": {
"bootstrap": "latest",
"bootstrap-datepicker": "latest",
"bootstrap-growl": "latest",
"bootstrapvalidator": "latest",
"jquery": "1.11.*",
"jquery-migrate": "latest",
"pwstrength-bootstrap": "latest",
"select2": "latest",
"font-awesome": "latest"
}
}
这是我添加的行/app/config/config.yml
#FkrCssURLRewriteBundle
fkr_css_url_rewrite:
rewrite_only_if_file_exists: true
clear_urls: true
# SpBowerBundle
sp_bower:
install_on_warmup: true
allow_root: true
assetic:
enabled: true
nest_dependencies: false
filters:
packages:
bootstrap:
css:
- css_url_rewrite
font_awesome:
css:
- css_url_rewrite
bundles:
TemplateBundle: ~
这是我现在遇到的错误:
"NetworkError: 404 Not Found - http://tanane.dev/select2.png"
"NetworkError: 404 Not Found - http://tanane.dev/select2-spinner.gif"
Why?
SpBowerBundle 中禁用 Assetic
我已在 SpBowerBundle 中禁用 assetic/app/config/config.yml
:
# SpBowerBundle
sp_bower:
install_on_warmup: true
allow_root: true
bundles:
TemplateBundle: ~
由于我使用 assetic 和 SpBowerBundle 来处理库依赖项,所以我重写了 CSS/JS 块base.html.twig
如下:
{% stylesheets
'bundles/template/components/bootstrap/dist/css/bootstrap.min.css'
'bundles/template/components/bootstrap/dist/css/bootstrap-theme.min.css'
'bundles/template/components/font-awesome/css/font-awesome.min.css'
'bundles/template/components/select2/select2.css'
'bundles/template/css/select2-bootstrap.css'
'bundles/template/components/bootstrapvalidator/dist/css/bootstrapValidator.min.css'
'bundles/template/components/bootstrap-datepicker/css/datepicker.css'
'bundles/template/components/bootstrap-datepicker/css/datepicker3.css'
'bundles/template/css/tanane.css'
filter='css_url_rewrite'
%}
<link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}
然后我清除缓存并运行命令assets:install --symlink
, assetic:dump
and assetic:dump --env=prod
仍然看不到图像和 FontAwesome 字体:
Failed to load resource: the server responded with a status of 404 (Not Found) http://tanane.dev/app_dev.php/css/select2.png
Failed to load resource: the server responded with a status of 404 (Not Found) http://tanane.dev/app_dev.php/css/select2-spinner.gif
Failed to load resource: the server responded with a status of 404 (Not Found) http://tanane.dev/app_dev.php/css/select2.png
Failed to load resource: the server responded with a status of 404 (Not Found) http://tanane.dev/app_dev.php/fonts/fontawesome-webfont.woff?v=4.2.0
Failed to load resource: the server responded with a status of 404 (Not Found) http://tanane.dev/app_dev.php/fonts/fontawesome-webfont.ttf?v=4.2.0
Failed to load resource: the server responded with a status of 404 (Not Found) http://tanane.dev/app_dev.php/fonts/fontawesome-webfont.svg?v=4.2.0#fontawesomeregular
我还想念其他东西吗?为了解决这个恼人的问题我还能做什么?
修复禁用方式
我修正了一些错误SpBowerBundle
配置,现在我有这个:
sp_bower:
install_on_warmup: true
allow_root: true
assetic:
enabled: false
nest_dependencies: false
bundles:
TemplateBundle: ~
但是图像,由SpBowerBundle
还是没有显示,请看附图:
I have assetic
在我的中启用config.yml
:
assetic:
debug: "%kernel.debug%"
use_controller: false
bundles:
- FrontendBundle
- BackendBundle
- ProductBundle
- CommonBundle
- UserBundle
- TemplateBundle
我应该禁用它并从那里删除所有这些捆绑包吗?
另一个测试
根据@lenybenard的建议,我这样做了:
{% block stylesheets %}
{% stylesheets filter='css_url_rewrite'
'bundles/template/components/font-awesome/css/font-awesome.min.css'
'bundles/template/components/bootstrap/dist/css/bootstrap.min.css'
'bundles/template/components/bootstrap/dist/css/bootstrap-theme.min.css'
filter='cssrewrite'
%}
<link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}
{% stylesheets
'bundles/template/components/select2/select2.css'
'bundles/template/css/select2-bootstrap.css'
'bundles/template/components/bootstrapvalidator/dist/css/bootstrapValidator.min.css'
'bundles/template/components/bootstrap-datepicker/css/datepicker.css'
'bundles/template/components/bootstrap-datepicker/css/datepicker3.css'
'bundles/template/css/tanane.css'
filter='cssrewrite'
filter='css_url_rewrite'
%}
<link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}
{% endblock %}
再次重复相同的过程:
- 清除缓存
cache:clear & cache:warmup
并且rm -rf /var/cache & rm -rf /var/logs
万一
- 来自 Symofony2 shell:
assets:install --symlink & assetic:dump & assetic:dump --env=prod
结果:在 DEV 中一切都很好,在 PROD 中一切都是错误的