1

我正在尝试合并 FOSFacebookBundle 和 FOSUserBundle。单独的 FosUserBundle 运行良好,但是当我尝试将 facebookbundle 与他集成时,我遇到了路由错误。我使用的是 Symfony 2.3.4

无法从“C:/xampp/htdocs/Symfonia/app/config\routing.yml”导入资源“@FOSFacebookBundle/Resources/config/routing.xml”。确保“FOSFacebookBundle/Resources/config/routing.xml”包已正确注册并加载到应用程序内核类中。

我在 routing.yml 的每个地方都有 4 个空格键。当然,我在 AppKernel.php 中实现了它

我的路由.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
_welcome:
    pattern:  /
    defaults: { _controller: AcmeUserBundle:Welcome:index }

_security_check:
    pattern:  /login_fb_check
_security_logout:
    pattern:  /logout
fos_facebook_channel:
    resource: "@FOSFacebookBundle/Resources/config/routing.xml"

配置.yml

imports:
    - { resource: parameters.yml }
    - { resource: security.yml }
services:
    my.facebook.user:
        class: Acme\UserBundle\Security\User\Provider\FacebookProvider
        arguments:
            facebook: "@fos_facebook.api"
            userManager: "@fos_user.user_manager"
            validator: "@validator"
framework:
    #esi:             ~
    translator:      { fallback: %locale% }
    secret:          %secret%
    router:
        resource: "%kernel.root_dir%/config/routing.yml"
        strict_requirements: ~
    form:            ~
    csrf_protection: ~
    validation:      { enable_annotations: true }
    templating:
        engines: ['twig']
        #assets_version: SomeVersionScheme
    default_locale:  "%locale%"
    trusted_proxies: ~
    session:         ~
    fragments:       ~
    http_method_override: true

# Twig Configuration
twig:
    debug:            %kernel.debug%
    strict_variables: %kernel.debug%

# Assetic Configuration
assetic:
    debug:          %kernel.debug%
    use_controller: false
    bundles:        [ ]
    #java: /usr/bin/java
    filters:
        cssrewrite: ~
        #closure:
        #    jar: %kernel.root_dir%/Resources/java/compiler.jar
        #yui_css:
        #    jar: %kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar

# Doctrine Configuration
doctrine:
    dbal:
        driver:   %database_driver%
        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, add the path in parameters.yml
        # e.g. database_path: %kernel.root_dir%/data/data.db3
        # path:     %database_path%

    orm:
        auto_generate_proxy_classes: %kernel.debug%
        auto_mapping: true


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

fos_user:
    db_driver: orm
    firewall_name: main
    user_class: Acme\UserBundle\Entity\User
fos_facebook:
  alias:  facebook
  app_id: 123456879
  secret: s3cr3t
  cookie: true
  permissions: [email, user_birthday, user_location]

和我的security.yml

security:
    providers:
        chain_provider:
            chain:
                providers: [fos_user_bundle, my_fos_facebook_provider]
        fos_user_bundle:
            id: fos_user.user_provider.username
        my_fos_facebook_provider:
            id: my.facebook.user   
    encoders:
        FOS\UserBundle\Model\UserInterface: sha512

    firewalls:
        main:
            pattern: ^/
            form_login:
                provider: chain_provider
                csrf_provider: form.csrf_provider
            fos_facebook:
                app_url: "http://apps.facebook.com/appName/"
                server_url: "http://localhost/facebookApp/"
                login_path: /login
                check_path: /login_fb_check
                default_target_path: /
                provider: chain_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: ^/facebook/,           role: [ROLE_FACEBOOK] }
        - { path: ^/.*,                  role: [IS_AUTHENTICATED_ANONYMOUSLY] }


    role_hierarchy:
        ROLE_ADMIN:       ROLE_USER
        ROLE_SUPER_ADMIN: ROLE_ADMIN

谢谢你的帮助 !

4

3 回答 3

2

I had the same problem, solved just now.

It seems that the routing.xml file is not downloaded, search for it in the folder \vendor\friendsofsymfony\facebook-bundle\FOS\FacebookBundle\Resources\config of your app.

If is not here, then simply download it and copy it from the repository "https://github.com/FriendsOfSymfony/FOSFacebookBundle/blob/master/Resources/config/routing.xml"

routing.xml as below:

<?xml version="1.0" encoding="UTF-8" ?>

<routes xmlns="http://symfony.com/schema/routing"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">

    <route id="fos_facebook_channel" pattern="/channel.html">
        <default key="_controller">FOSFacebookBundle:Facebook:channel</default>
        <requirement key="_method">GET</requirement>
    </route>

</routes>
于 2013-09-25T12:51:35.153 回答
1

捆绑包匹配版本 1.2.* 的最新稳定版本似乎不包含路由文件,因此如果您使用 composer 并且最低稳定性设置为“稳定”(默认情况下),那么只需引用捆绑包允许这样的开发稳定性:

require {
    ...,
    "friendsofsymfony/facebook-bundle": "1.2.*@dev"
}

然后只需使用 composer 更新包:

php composer update friendsofsymfony/facebook-bundle

这样,当他们克隆 repo 并通过 composer 在他们自己的 locar 工作目录中安装 verdors 时,问题不会被复制到从事同一项目的其他开发人员。

于 2013-10-13T23:59:55.553 回答
-1

只需通过此链接并检查路由和配置文件的
FOSFacebookBundle 和 FOSUserBundle
以及更多描述
https://github.com/FriendsOfSymfony/FOSFacebookBundle/tree/2.0#include-the-login-button-in-your-templates

并制作确保
将此捆绑包添加到应用程序的内核:

 // app/ApplicationKernel.php
  public function registerBundles()
  {
      return array(
          // ...
          new FOS\FacebookBundle\FOSFacebookBundle(),
          // ...
      );
  }
于 2013-09-25T09:05:07.720 回答