symfony-fosuserbundle找不到" GET / login /"的路线删除了hwi-oauthbundle之后

时间:2017-06-22 12:50:49

标签: php symfony fosuserbundle

我搜索了很多stackoverflow页面并更新了我的源代码来解决这个问题。但我无法解决这个问题。我认为我在代码中遗漏了一些东西,或者我改变了一些东西。

当我尝试访问" / login"时。它会自动重定向到" / login /"

实际上我的网站安装了三个软件包。

  • FosUserBundle
  • EsayAdminBundle
  • HWI Bundle(稍后删除)

删除HWI oauth捆绑后,它包含了此错误

  

未找到" GET / login /" (来自" http://127.0.0.1:8000/")

这是我在Symfony的第一个项目。任何人都可以给我你的更正和建议。我提到了

  

Config.yml

imports:
    - { resource: parameters.yml }
    - { resource: security.yml }
    - { resource: services.yml }
    - { resource: "@BlogBundle/Resources/config/services.yml" }
    - { resource: "@UserBundle/Resources/config/services.yml" }

# Put parameters here that don't need to change on each machine where the app is deployed
# http://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
    locale: fr

framework:
    #Annotation enabled here 
    #validation: { enabled: true, enable_annotations: true }

    #esi:             ~
    translator:      { fallbacks: ["%locale%"] }
    secret:          "%secret%"
    router:
        resource: "%kernel.root_dir%/config/routing.yml"
        strict_requirements: ~
    form:            ~
    csrf_protection: ~
    validation:      { enable_annotations: true }
    #serializer:      { enable_annotations: true }
    templating:
        engines: ['twig']
    default_locale:  "%locale%"
    trusted_hosts:   ~
    trusted_proxies: ~
    session:
        # http://symfony.com/doc/current/reference/configuration/framework.html#handler-id
        handler_id:  session.handler.native_file
        save_path:   "%kernel.root_dir%/../var/sessions/%kernel.environment%"
    fragments:       ~
    http_method_override: true
    assets: ~
    php_errors:
        log: true

# Twig Configuration
twig:
    debug:            "%kernel.debug%"
    strict_variables: "%kernel.debug%"
    cache : false    
# Doctrine Configuration
doctrine:
    dbal:
        driver:   pdo_mysql
        host:     "%database_host%"
        port:     "%database_port%"
        dbname:   "%database_name%"
        user:     "%database_user%"
        password: "%database_password%"
        charset:  UTF8
        # if using pdo_sqlite as your database driver:
        #   1. add the path in parameters.yml
        #     e.g. database_path: "%kernel.root_dir%/../var/data/data.sqlite"
        #   2. Uncomment database_path in parameters.yml.dist
        #   3. Uncomment next line:
        #path:     "%database_path%"

    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        naming_strategy: doctrine.orm.naming_strategy.underscore
        auto_mapping: true


# Swiftmailer Configuration
swiftmailer:
    transport: "%mailer_transport%"
    host:      "%mailer_host%"
    username:  "%mailer_user%"
    password:  "%mailer_password%"
    spool:     { type: memory }


 # app/config/config.yml
fos_user:
    db_driver: orm # other valid values are 'mongodb' and 'couchdb'
    # other valid values are 'mongodb' and 'couchdb'
    firewall_name: main
    user_class: UserBundle\Entity\User

    from_email:
        address: "test@myblog.org"
        sender_name: "My-first-blog"


    registration:
        form:
            type: UserBundle\Form\RegistrationType


easy_admin:
    site_name: '<i class="fa fa-th" aria-hidden="true"></i> Hexagone - Espace Admin'
    entities:
        User: 
            label : Utilisateurs
            class : UserBundle\Entity\User
            list:
                fields: ['username', 'email', 'enabled', 'last_login', 'roles','code_postal']

        Projet :
            class: BlogBundle\ProjetBundle\Entity\projet
            label : Projets

    design:
        brand_color: '#333333'
  

的routing.yml

projet:
    resource: "@ProjetBundle/Resources/config/routing.yml"
    prefix:   /

blog_bundle_user:
    resource: "@UserBundle/Resources/config/routing.yml"
    prefix:   / 

blog:
    resource: "@BlogBundle/Resources/config/routing.yml"
    prefix:   /

app:
    resource: "@AppBundle/Controller/"
    type:     annotation

fos_user:
    resource: "@FOSUserBundle/Resources/config/routing/all.xml"

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

easy_admin_bundle:
    resource: "@EasyAdminBundle/Controller/AdminController.php"
    type:     annotation
    prefix:   /backoffice
  

security.yml

security:
    encoders:
        FOS\UserBundle\Model\UserInterface: bcrypt

    role_hierarchy:
        ROLE_ADMIN:       ROLE_USER
        ROLE_SUPER_ADMIN: ROLE_ADMIN

    providers:
        fos_userbundle:
            id: fos_user.user_provider.username

    firewalls:
        main:
            pattern: ^/
            form_login:
                provider: fos_userbundle
                csrf_token_generator: security.csrf.token_manager
                login_path: /login
                check_path: /login_check
                default_target_path:            /profile
                # if you are using Symfony < 2.8, use the following config instead:
                # csrf_provider: form.csrf_provider

            logout:       true
            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 }
        - { path: ^/backoffice, role: ROLE_ADMIN }
  

services.yml

服务:     app.form.registration:         class:UserBundle \ Form \ RegistrationType         标签:              - {name:form.type,alias:app_user_registration}

  

所有路线

_wdt                                ANY        ANY      ANY    /_wdt/{token}
  _profiler_home                      ANY        ANY      ANY    /_profiler/
  _profiler_search                    ANY        ANY      ANY    /_profiler/search
  _profiler_search_bar                ANY        ANY      ANY    /_profiler/search_bar
  _profiler_info                      ANY        ANY      ANY    /_profiler/info/{about}
  _profiler_phpinfo                   ANY        ANY      ANY    /_profiler/phpinfo
  _profiler_search_results            ANY        ANY      ANY    /_profiler/{token}/search/results
  _profiler_open_file                 ANY        ANY      ANY    /_profiler/open
  _profiler                           ANY        ANY      ANY    /_profiler/{token}
  _profiler_router                    ANY        ANY      ANY    /_profiler/{token}/router
  _profiler_exception                 ANY        ANY      ANY    /_profiler/{token}/exception
  _profiler_exception_css             ANY        ANY      ANY    /_profiler/{token}/exception.css
  _twig_error_test                    ANY        ANY      ANY    /_error/{code}.{_format}
  projet_homepage                     ANY        ANY      ANY    /projet
  blog_bundle_user_homepage           ANY        ANY      ANY    /
  blog_homepage                       ANY        ANY      ANY    /
  githut                              ANY        ANY      ANY    /
  homepage                            ANY        ANY      ANY    /
  fos_user_security_login             GET|POST   ANY      ANY    /login
  fos_user_security_check             POST       ANY      ANY    /login_check
  fos_user_security_logout            GET|POST   ANY      ANY    /logout
  fos_user_profile_show               GET        ANY      ANY    /profile/
  fos_user_profile_edit               GET|POST   ANY      ANY    /profile/edit
  fos_user_registration_register      GET|POST   ANY      ANY    /register/
  fos_user_registration_check_email   GET        ANY      ANY    /register/check-email
  fos_user_registration_confirm       GET        ANY      ANY    /register/confirm/{token}
  fos_user_registration_confirmed     GET        ANY      ANY    /register/confirmed
  fos_user_resetting_request          GET        ANY      ANY    /resetting/request
  fos_user_resetting_send_email       POST       ANY      ANY    /resetting/send-email
  fos_user_resetting_check_email      GET        ANY      ANY    /resetting/check-email
  fos_user_resetting_reset            GET|POST   ANY      ANY    /resetting/reset/{token}
  fos_user_change_password            GET|POST   ANY      ANY    /profile/change-password
  easyadmin                           ANY        ANY      ANY    /backoffice/
  admin                               ANY        ANY      ANY    /backoffice/

很抱歉缩进,我粘贴代码时可能错过了。 Whatelse需要解决这个问题吗?我可以粘贴在这里。

注意:我也试过我的旧版本,这不是hwi-oauth捆绑的。它解决了同样的问题。

我再次浏览了fosbundle安装页面。我没有任何线索。

1 个答案:

答案 0 :(得分:0)

您似乎正在尝试访问应用中的路径/login/,但只有路径fos_user_security_login定义路径为/login(不会尾随/

/login/RouteMatcher这种方式不匹配。您还需要定义第二条路径以匹配此路径。