【发布时间】:2014-10-29 10:00:33
【问题描述】:
我正在尝试建立一个我在共享主机上工作的网站,一切正常,但 FontAwesome 图标因为 Symfony 没有找到它们应该在的位置。我按照以下步骤将站点移至生产共享主机:
- 将资产发布为硬拷贝,因为 SH 不允许符号链接,所以我运行此命令
assets:install - 通过运行以下命令发布由 Assetic 处理的资产:
assetic:dump(dev) 和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,我也找到了this interesting 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"
为什么?
在 SpBowerBundle 中禁用资产
我在 /app/config/config.yml 的 SpBowerBundle 中禁用了资产:
# SpBowerBundle
sp_bower:
install_on_warmup: true
allow_root: true
bundles:
TemplateBundle: ~
由于我使用资产和 SpBowerBundle 来处理库依赖项,因此我在 base.html.twig 重写 CSS/JS 块,如下所示:
{% 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 和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管理的图片仍然没有显示,见附图:
我在config.yml 中启用了assetic:
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 外壳:
assets:install --symlink & assetic:dump & assetic:dump --env=prod
结果:在 DEV 中一切正常,在 PROD 中一切错误
【问题讨论】:
-
如果您不使用默认的
web路径,请尝试app/console assets:install path。 -
@Mr.Smith 我正在使用默认网络路径
-
能否请您发布您定义这些资产的树枝模板部分并创建链接标签以包含它们
-
@TomCorrigan 添加到主帖,看看
-
@TomCorrigan 你能看看我添加到主帖中的信息吗?我仍然有这方面的问题