php - Symfony is changing where it's looking for assets depending on url -
symfony looks looking assets in relative location based on url path navigate to. assets load , applied correctly when navigate "first-level" path such example.com/mpre
, example.com/test
, example.com/foo
, of assets 404 when navigate "second-level" url such example.com/mpre/test
, example.com/test/foo
, example.com/foo/bar
. why this? there way framework in 1 spot assets regardless of url?
i have 2 urls
example.com/mpre example.com/mpre/test
my assets (css, js) load fine on first url, example.com/mpre
, of them 404 when navigate second url, example.com/mpre/test
when go inspector on each page see path assets, see following:
example.com/bundles/app/css/023f7f6_style.css_4.css //example.com/mpre 200 ok response example.com/mpre/bundles/app/css/c8b625f_style.css_3.css //example.com/mpre/test 404 not found response
in config.yml
have following line assetic:
assetic: write_to: %kernel.root_dir%/../web/bundles/app/
additional information
- i not using
cssrewrite
filter
edit 1
- i installed symfony 2.3 via composer
im including css in base.html.twig , using assetic compile them
{% stylesheets '@appbundle/resources/assets/css/bootstrap_loader.css.scss' '@appbundle/resources/assets/css/stately/*' '@appbundle/resources/assets/css/bootstrapvalidator.min.css' '@appbundle/resources/assets/css/style.css.scss' '@appbundle/resources/assets/css/learners.css' %}
the paths standard routes. each path corresponds controller action renders view
here view looks when assets 404
- here dump of
./app/console config:dump-reference assetic
default configuration extension alias: "assetic"
assetic: debug: %kernel.debug% use_controller: enabled: %kernel.debug% profiler: false read_from: %kernel.root_dir%/../web write_to: %assetic.read_from% java: /usr/bin/java node: /usr/bin/node node_paths: [] ruby: /home/ubuntu/.rvm/rubies/ruby-2.0.0-p195/bin/ruby sass: /home/ubuntu/.rvm/gems/ruby-2.0.0-p195/bin/sass variables:
# prototype name: [] bundles: # defaults: - frameworkbundle - securitybundle - twigbundle - monologbundle - swiftmailerbundle - asseticbundle - doctrinebundle - sensioframeworkextrabundle - appbundle - lswmemcachebundle - webprofilerbundle - sensiodistributionbundle - sensiogeneratorbundle assets: # prototype name: inputs: [] filters: [] options: # prototype name: [] filters: # prototype name: [] workers: cache_busting: enabled: false twig: functions: # prototype name: []
edit 2
i've found source of problem. link path relative, changed use baseurl. <script src="{{ app.request.baseurl }}/bundles/app{{ asset_url }}"></script>
, works great.
i'm assuming there issue write_to setting.
try these settings , see happens.
assetic: read_from: '%kernel.root_dir%/../web' write_to: '%assetic.read_from%'
these should default assetic config settings read_from , write_to.
your settings show %kernel.root_dir%/../web/bundles/app/
. assetic generate bundles folders automatically, setting own bundles
folder causing unexpected results.
in bundles/
, app
corresponds bundle appbundle
. bundle named foobundle
have it's assets in web/bundles/foo/
etc.
make sure clear symfony cache after making changes config file.
Comments
Post a Comment