[英]Symfony assetic doesn't work
Here are my files configured to make every thing functionnal (but it's not ). 这是我的文件,配置为使所有功能正常工作(但不是)。 I did a cache clear, a
php app/console assests:intall web
, nothing new. 我做了一个缓存清除,一个
php app/console assests:intall web
,没有什么新内容。 Always getting this error message: Cannot load resource "."
总是收到此错误消息:
Cannot load resource "."
. 。
twig:
paths:
"%kernel.root_dir%/../src/Acme/TestBundle": AcmeTestBundle
assetic:
debug: "%kernel.debug%"
use_controller: false
bundles: [AcmeTestBundle]
assetic:
use_controller: false
_assetic:
resource: .
type: assetic
{% javascripts '@AcmeTestBundle/Resources/public/js/main.js' %}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}
console.log('hello');
Does anyone know if I'm missing something in the config or in my twig files to make the route finally findable :P ? 有谁知道我是否在配置或我的树枝文件中缺少某些东西来使路由最终可被找到:P? Thank you guys.
感谢大伙们。
try to configure like this: 尝试这样配置:
1- Put your resources in the "public" folder, is found in: 1-将您的资源放在“公共”文件夹中,该文件夹位于:
YourBundle/Resources/config/public/css
YourBundle/Resources/config/public/js
YourBundle/Resources/config/public/images
YourBundle/Resources/config/public/fonts
2- In some projects I use Yuicompressor for Assetic, (Yuicompressor 2.4.7 works well on windows platform) and put the yuicompressor-2.4.7.jar in: 2-在某些项目中,我使用Yuicompressor for Assetic(Yuicompressor 2.4.7在Windows平台上运行良好)并将yuicompressor-2.4.7.jar放在:
app/Resources/java/yuicompressor-2.4.7.jar
Important: yuicompressors requires java runtime environment 1.7, as usal it is installed in the C:\\Program Files (x86)\\Java\\jre7\\bin (Win64Bits) 重要提示: yuicompressors需要Java运行时环境1.7,因为它通常安装在C:\\ Program Files(x86)\\ Java \\ jre7 \\ bin(Win64Bits)中
3- Setting the config.yml 3-设置config.yml
...
assetic:
debug: "%kernel.debug%"
use_controller: false
bundles: [ ]
java: "C:/Program Files (x86)/Java/jre7/bin/java.exe"
filters:
cssrewrite: ~
#closure:
# jar: "%kernel.root_dir%/Resources/java/compiler.jar"
yui_css:
jar: "%kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar"
yui_js:
jar: "%kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar"
...
4- Using the stylesheets and javascripts blocks in a templete twig 4-在模板树枝中使用样式表和javascript块
for your css files you can use: 对于您的CSS文件,您可以使用:
{% stylesheets
'bundles/app/css/styles.css'
'bundles/app/css/others.css'
filter='?yui_css, cssrewrite'
output='css/common-stylesheets.css' %}
<link href="{{ asset_url }}" rel="stylesheet" />
{% endstylesheets %}
for your javascripts file you can use: 对于您的javascripts文件,您可以使用:
{% javascripts
'@AppBundle/Resources/public/js/myApp.js'
'@AppBundle/Resources/public/js/otherFiles.js'
filter='?yui_js'
output='js/common-javascripts.js' %}
<script src="{{ asset_url }}" type="text/javascript"></script>
{% endjavascripts %}
5- Running commands Symfony 5-运行命令Symfony
app/console cache:clear
app/console cache:clear --env=prod
app/console assets:install web
app/console assetic:dump
app/console assetic:dump --env=prod
6- Check files created 6-检查创建的文件
if you go to the web folder in your symfony project, you can see the next files: 如果转到symfony项目中的Web文件夹,则可以看到以下文件:
web/css/common-stylesheets.css
web/javascript/common-javascripts.js
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.