douxun7992 2015-11-13 21:53
浏览 16

Symfony资产不起作用

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. Always getting this error message: Cannot load resource ".".

app/config.php

twig:
  paths:
    "%kernel.root_dir%/../src/Acme/TestBundle": AcmeTestBundle
assetic:
  debug:          "%kernel.debug%"
  use_controller: false
  bundles:        [AcmeTestBundle]

app/config_dev.php

assetic:
  use_controller: false

app/routing_dev.php

_assetic:
  resource: .
  type:     assetic

src/Acme/TestBundle/Resources/views/Default/index.html.twig

{% javascripts '@AcmeTestBundle/Resources/public/js/main.js'  %}
  <script src="{{ asset_url }}"></script>
{% endjavascripts %}

src/Acme/TestBundle/Resources/public/js/main.js

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 ? Thank you guys.

  • 写回答

1条回答 默认 最新

  • duanhuilao0787 2015-11-14 23:37
    关注

    try to configure like this:

    1- Put your resources in the "public" folder, is found in:

     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:

    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)

    3- Setting the 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

    for your css files you can use:

    {% 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           
        '@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

    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

    if you go to the web folder in your symfony project, you can see the next files:

    web/css/common-stylesheets.css
    web/javascript/common-javascripts.js
    
    评论

报告相同问题?

悬赏问题

  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入