我是Symfony2的初学者,我在设置像css,js,images这样的资源方面遇到了一些问题......我刚刚阅读本文档如何使用Assetic 但我无法弄清楚什么是放置资产的最佳方法.那篇文章告诉我,我应该将js文件放在我的Bundle中,但是将css文件放在/ web/public/css中(在Bundle外面).这是复杂和不便的.有人能告诉我吗?谢谢
我正在尝试让Symfony2与jQuery UI一起工作.我已经让它的JavaScript部分运行得很好,但我无法让图像工作.
我在Assetic文档中读到的一件事是,cssrewrite过滤器可以获取CSS文件中的图像路径并更新它们,使路径指向正确的位置.这看起来就像我需要的,所以我启用了cssrewrite.这是cssrewrite改变我的路径的方式:
// original
images/ui-icons_222222_256x240.png
// using cssrewrite
../../../app/Resources/public/css/themes/base/images/ui-icons_222222_256x240.png
Run Code Online (Sandbox Code Playgroud)
第一条道路并不好.该cssrewrite路径至少指向文件系统中的正确路径,但相对于我的webroot,cssrewrite路径是WAY off.显然我的app目录不公开.
如何让cssrewrite过滤器将路径更改为实际可用的路径?
这是我的样式表包含.(是的,我知道我单独包括所有这些CSS文件的方式是愚蠢的,但现在我不担心这种权利.)
{% stylesheets
'../app/Resources/public/css/*'
'../app/Resources/public/css/themes/base/jquery.ui.accordion.css'
'../app/Resources/public/css/themes/base/jquery.ui.all.css'
'../app/Resources/public/css/themes/base/jquery.ui.autocomplete.css'
'../app/Resources/public/css/themes/base/jquery.ui.base.css'
'../app/Resources/public/css/themes/base/jquery.ui.button.css'
'../app/Resources/public/css/themes/base/jquery.ui.core.css'
'../app/Resources/public/css/themes/base/jquery.ui.datepicker.css'
'../app/Resources/public/css/themes/base/jquery.ui.dialog.css'
'../app/Resources/public/css/themes/base/jquery.ui.progressbar.css'
'../app/Resources/public/css/themes/base/jquery.ui.resizable.css'
'../app/Resources/public/css/themes/base/jquery.ui.selectable.css'
'../app/Resources/public/css/themes/base/jquery.ui.slider.css'
'../app/Resources/public/css/themes/base/jquery.ui.tabs.css'
'../app/Resources/public/css/themes/base/jquery.ui.theme.css'
%}
<link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}
Run Code Online (Sandbox Code Playgroud) 我正在尝试了解symfony2资产包.我正在尝试使用一个jquery插件,它使用它自己的css文件.我把所有内容都放进去mybundle/Resources/public然后拆分成images/javascript /和css /
插件css使用相对路径来获取图像 ../images/sprite.png
使用assetic来提供css文件:
{% stylesheets
'@MyBundle/Resources/public/css/mycss.css'
%}
<link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}
Run Code Online (Sandbox Code Playgroud)
资产生成的路径/app_dev.php/css/mycss.css,我猜是正确的.显然,现在相对的图像不再起作用了.因为文件本身位于mybundle/Resources/public而不是/ images /
当尝试使用cssrewrite过滤器时,pathes会被重写为:
http://server.com/Resources/public/images/sprite.png.但我不正确,文件不在那里.
如何使用资产相对地提供图像?
我有一个关于symfony2和bootstrap的问题.我不明白为什么我可以从环境"prod"加载图标图像,但不能从环境"dev"加载.在开发中,我收到此错误.
路线是"GET /img/glyphicons-halflings.png".
Image web/img/glyphicons-halflings.png是../../vendor/twitter/bootstrap/img/glyphicons-halflings.png的符号链接
我得到这个错误
http://my.web.site/app_dev.php/img/glyphicons-halflings.png
Run Code Online (Sandbox Code Playgroud)
并获得图像
http://my.web.site/img/glyphicons-halflings.png
Run Code Online (Sandbox Code Playgroud)
UPDATE
我以这种方式包含bootstrap:
{% stylesheets '%kernel.root_dir%/../vendor/twitter/bootstrap/less/bootstrap.less' %}
<link rel="stylesheet" type="text/css" href="{{ asset_url }}" />
{% endstylesheets %}
Run Code Online (Sandbox Code Playgroud)
当我在prod使用时,这是有效的
<span class="icon-edit"></span>
Run Code Online (Sandbox Code Playgroud)
我有这个资产配置:
assetic:
debug: %kernel.debug%
use_controller: false
bundles: [ MyAwesomeBundle ]
filters:
lessphp:
file: %kernel.root_dir%/../vendor/leafo/lessphp/lessc.inc.php
apply_to: "\.less$"
Run Code Online (Sandbox Code Playgroud)
我也试过创建我的收藏:
assetic:
assets:
senso:
inputs:
- '../img/glyphicons-halflings.png'
outputs:
- 'img/glyphicons-halflings.png'
filters:
- ?lessphp
Run Code Online (Sandbox Code Playgroud)
:dump create web/assetic/senso.png和web/assetic/senso_glyphicons-halflings.png但是,...如何使用senso*.png图像?
使用symphony框架我做了转储资产资产:安装.css文件很难复制到/web/bundles/appbundle/css/style.css我猜css中的背景图像我应该有一个相对路径到达/ web /文件夹之外吗?
background-image: url(../../../../bundles/appbundle/images/top_bg.jpg);
Run Code Online (Sandbox Code Playgroud)
但它还没有用,我在css标签中也有filter ='cssrewrite'.可能我必须补充一点,我只是在资源安装后编辑位于上面路径的css文件,我没有编辑/ Acme/Bundle/Resources/public/css中的那个.然后我确实运行了资产:dump,现在在/ web /文件夹中有两个文件夹用于图像和css,我查看了新的css并看到路径变成这样:
background-image: url(../../bundles/applicationadmin/images/top_bg.jpg);
Run Code Online (Sandbox Code Playgroud)
但仍然所有图像都被破坏了.我搜索stackoverflow并发现了这个问题,但仍然有问题.我该怎么办?
请指教.