Symfony 2 : CSS and JS not loaded using FosUserBundle routing (Bad links)

会有一股神秘感。 提交于 2019-12-11 20:32:38

问题


*Hello there, I come here cause i found 0 solutions from now ... I started using FosUserBundle and was enjoying the functionalities ! But cause there is a but ... :p

When i try to go in the login page it's ok : app_dev.php/login

Now i try all the other links : /profile - /register - /resetting no one can load css and js ...

So i search why and i find this :

From /login i need to do ../css/images or ../js/vendor for exemple

From /register or the two other links i need to do ../../css/images or ../../js/vendor

Why this change ? why Symfony cannot load css and js from the same path ? It's annoying cause working like this i can't see and modify the templates easily on fosuserbundle.

I only modified routing.yml and security.yml :

# routing.yml
fos_user_security:
    resource: "@FOSUserBundle/Resources/config/routing/security.xml"

fos_user_profile:
    resource: "@FOSUserBundle/Resources/config/routing/profile.xml"
    prefix: /profile

fos_user_register:
    resource: "@FOSUserBundle/Resources/config/routing/registration.xml"
    prefix: /register

fos_user_resetting:
    resource: "@FOSUserBundle/Resources/config/routing/resetting.xml"
    prefix: /resetting

fos_user_change_password:
    resource: "@FOSUserBundle/Resources/config/routing/change_password.xml"
    prefix: /profile

And then security

# app/config/security.yml
security:
encoders:
    FOS\UserBundle\Model\UserInterface: sha512

role_hierarchy:
    ROLE_ADMIN:       ROLE_USER
    ROLE_SUPER_ADMIN: ROLE_ADMIN

providers:
    fos_userbundle:
        id: fos_user.user_provider.username

firewalls:
    dev:
        pattern:  ^/(_(profiler|wdt)|css|images|js)/
        security: false
    main:
        pattern:          ^/
        form_login:
            check_path:   /login_check
            login_path:   /login
            provider:     fos_userbundle
        logout:
            path:         /logout
            target:       /
          # provider: fos_userbundle
          # csrf_provider: form.csrf_provider
        remember_me:
            key:         %secret%
            lifetime:    300000000
            path: /
            domain :     ~
        anonymous:        true

access_control:
    - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/admin/, role: ROLE_ADMIN }

If someone have an idea or the same resolved issue ;) Thanks in advance and have a nice day !!

来源:https://stackoverflow.com/questions/30194433/symfony-2-css-and-js-not-loaded-using-fosuserbundle-routing-bad-links

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!