2017 © Pedro Peláez
 

symfony-bundle facebook-bundle

Create a Facebook app into your Symfony2 application.

image

earlybirds/facebook-bundle

Create a Facebook app into your Symfony2 application.

  • Wednesday, February 11, 2015
  • by harscoet
  • Repository
  • 4 Watchers
  • 0 Stars
  • 93 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

EBFacebookBundle

  1. Add the following lines in your composer.json:, (*1)

    {
        "require": {
            "friendsofsymfony/facebook-bundle": "dev-master",
            "friendsofsymfony/user-bundle": "dev-master",
            "earlybirds/facebook-bundle": "dev-master"
        }
    }
    
  2. Run the composer to download the bundle:, (*2)

    $ php composer.phar update
    
  3. Add bundles to your application's kernel:, (*3)

    // app/ApplicationKernel.php
    public function registerBundles()
    {
        return array(
            // ...
            new FOS\FacebookBundle\FOSFacebookBundle(),
            new FOS\UserBundle\FOSUserBundle(),
            new EB\FacebookBundle\EBFacebookBundle(),
            // ...
        );
    }
    
  4. Add the following routes to your application and point them at actual controller actions, (*4)

    #app/config/routing.yml
    eb_facebook:
        resource: "@EBFacebookBundle/Resources/config/routing.xml"
    
    <!-- app/config/routing.xml -->
    <import resource="@EBFacebookBundle/Resources/config/routing.xml"/>
    
  5. Configure the eb_facebook service in your config:, (*5)

    #app/config/config.yml
    framework:
        translator: ~
    
    eb_facebook:
        app_id: 123456879 #Facebook application ID
        secret: s3cr3t #Facebook application secret
        templates:
            layout:  AcmeDemoBundle::layout.html.twig #Your personnal layout
            home:  AcmeDemoBundle:Demo:home.html.twig #Your personnal home view
            register:  AcmeDemoBundle:Demo:register.html.twig #Your personnal register view
        permissions: [email, user_birthday, user_location] #(Optional) Permissions of the app, if not configured set to default permissions
        fixcookie: https://host_of_facebook_application/fixcookie.php #(Optional) Url to a fix script to debug safari iframe on Facebook
        tab_url: https://www.facebook.com/MYCOMPANY/app_99999999999 #(Optional) Url of your Facebook tab page
        user_class: Acme\DemoBundle\Entity\User #(Optional) Namespace of your own Entity User class, default : EB\FacebookBundle\Entity\User
        form_class: Acme\DemoBundle\Form\UserType #(Optional) Namespace of your own Form User class, default : EB\FacebookBundle\Form\UserType
        translation: AcmeDemoBundle #(Optional) Change the translation domain, default : EBFacebookBundle
        culture: en_EN #(Optional) Facebook language, default : fr_FR
    
    

    If you have configured the fixcookie url, add to the web folder, the following PHP script, (*6)

    // web/fixcookie.php
    
    
  6. Update the base:, (*7)

    $ php app/console doctrine:schema:update --force
    
  7. Install assets:, (*8)

    $ php app/console assets:install web
    

    In dev you can use the symlink option, (*9)

    $ php app/console assets:install --symlink
    
  8. In prod you can dump assets:, (*10)

    $ php app/console assetic:dump --env=prod --no-debug
    
  9. Add this configuration if you want to use the security component:, (*11)

    # app/config/security.yml
    security:
        encoders:
            Symfony\Component\Security\Core\User\User: plaintext
            FOS\UserBundle\Model\UserInterface: sha512
    
        role_hierarchy:
            ROLE_USER:       ROLE_FACEBOOK
            ROLE_ADMIN:       ROLE_USER
            ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
    
        providers:
            fos_userbundle:
                id: fos_user.user_provider.username_email
            facebook:
                id: eb_facebook.provider
    
        firewalls:
            dev:
                pattern:  ^/(_(profiler|wdt)|css|images|js)/
                security: false
    
            main:
                pattern: ^/
                fos_facebook:
                    app_url: "https://www.facebook.com/MYCOMPANY/app_99999999999" #You facebook app url
                    server_url: "https://host_of_facebook_application" #Url of your server url
                    check_path: _security_check
                    provider: facebook
                    default_target_path: eb_facebook_register
                logout:
                    path:   _security_logout
                    invalidate_session: false
                anonymous:    true
    
        access_control:
            - { path: ^/register, role: [ROLE_FACEBOOK] }
            - { path: ^/user_count, role: [ROLE_FACEBOOK] }
            - { path: ^/game, role: [ROLE_FACEBOOK] } #The route of the third page of the app (after home and validation of the form)
    
    
  10. Create your layout with your own logic extending the EBFacebook layout, (*12)

    ```html+jinja {% extends 'EBFacebookBundle::layout.html.twig' %}, (*13)

    {% block stylesheets %} {{ parent() }} {% stylesheets 'bundles/acmedemo/css/style.css' filter='cssrewrite' %} {% endstylesheets %} {% endblock %}, (*14)

    {% block javascripts %} {{ parent() }} {% javascripts 'bundles/acmedemo/js/ebfacebook.js' %} {% endjavascripts %} {% endblock %}, (*15)

    {% block title %}My application faceook title{% endblock title %}, (*16)

    {% block footer_content %} Footer content example {% endblock footer_content %} ```, (*17)

  11. Create your home view with your own logic extending YOUR layout you have just created, (*18)

    ```html+jinja {% extends 'AcmeDemoBundle::layout.html.twig' %}, (*19)

    {% block body %}, (*20)

    My home text
    {{ facebook_custom_login_button() }}

    {% endblock %} ```, (*21)

  12. Create your register view with your own logic extending the EBFacebook register view, (*22)

    ```html+jinja {% extends 'EBFacebookBundle:Facebook:register.html.twig' %}, (*23)

    {% block form %}, (*24)

    Register to continue

    Fill the fields
    * mandatory fields
    {{ form_errors(form) }}
    {{ form_row(form.lastname) }}
    {{ form_row(form.firstname) }}
    {{ form_row(form.birthday) }}
    {{ form_row(form.email) }}
    {{ form_row(form.address) }}
    {{ form_row(form.zipcode_fr) }}
    {{ form_row(form.city) }}
    {{ form_row(form.phone) }}
    {{ form_row(form.readConditions) }}
    I accept to receive offers
    {{ form_row(form.offersEmail) }}
    {{ form_row(form.offersSms) }}

    {% endblock %} ```, (*25)

  13. Create your game view with your own logic extending YOUR layout, (*26)

    ```html+jinja {% extends 'AcmeDemoBundle::layout.html.twig' %}, (*27)

    {% block body %} {% endblock %} ```, (*28)

  14. Create the action for the game view in your controller, you have to name your route "game", (*29)

    // src/Acme/DemoBundle/Controller/DemoController.php
    
    class DemoController extends Controller
    {
        /**
         * @Route("/game", name="game") //You have to name your route "game"
         * @Template()
         */
        public function gameAction()
        {
            /*
                Some code
            */
            return array(
            );
        }
    }
    

The Versions