0
votes

I'm following a tutorial to install this FOSUserBundle to my project. I got my information from this french tutorial: http://www.tutodidacte.com/symfony2-installer-fosuserbundle

So I did those commands:

php ./composer.phar require friendsofsymfony/user-bundle "~2.0@dev" 
php composer.phar update

Then I created a new Bundle,

php bin/console generate:bundle
Bundle Namespace : Kingdom/UserBundle

But after doing that, in the AppKernel i can see the new UserBundle, mais the FOSUserBundle isn't here.

I try to add it by myself writting it in the file; but after when i try to create an entity we can see something is clearly wrong.

Sorry for the presentation of this below...I haven't succeed to print it correctly.

php bin/console generate:doctrine:entity

Fatal error: Uncaught exception 'Symfony\Component\Config\Definition\Exception\I nvalidConfigurationException' with message 'The child node "db_driver" at path " fos_user" must be configured.' in C:\wamp\www\Kingdom\vendor\symfony\symfony\src \Symfony\Component\Config\Definition\ArrayNode.php:240 Stack trace:

0 C:\wamp\www\Kingdom\vendor\symfony\symfony\src\Symfony\Component\Config\Defin

ition\BaseNode.php(303): Symfony\Component\Config\Definition\ArrayNode->finalize Value(Array)

1 C:\wamp\www\Kingdom\vendor\symfony\symfony\src\Symfony\Component\Config\Defin

ition\Processor.php(37): Symfony\Component\Config\Definition\BaseNode->finalize( Array)

2 C:\wamp\www\Kingdom\vendor\symfony\symfony\src\Symfony\Component\Config\Defin

ition\Processor.php(50): Symfony\Component\Config\Definition\Processor->process( Object(Symfony\Component\Config\Definition\ArrayNode), Array)

3 C:\wamp\www\Kingdom\vendor\friendsofsymfony\user-bundle\DependencyInjection\F

OSUserExtension.php(51): Symfony\Component\Config\Definition\Processor->processC onfigur in C:\wamp\www\Kingdom\vendor\symfony\symfony\src\Symfony\Component\Conf ig\Definition\ArrayNode.php on line 240

2
try to configure config.yml correctly, if It doesn't work again try to post your config.yml file here please - Alessandro Minoccheri
How do I know if the config.yml is correctly configured ? - user8238012

2 Answers

0
votes

It seems you haven't properly configured the bundle. Follow the steps here: http://symfony.com/doc/current/bundles/FOSUserBundle/index.html

In your case, it seems you are missing at least this: http://symfony.com/doc/current/bundles/FOSUserBundle/index.html#step-5-configure-the-fosuserbundle

EDIT: After reading your question again, it seems you're not loading the bundle properly, as described here: http://symfony.com/doc/master/bundles/FOSUserBundle/index.html#step-2-enable-the-bundle

0
votes

After Installation A bundle needs to be enabled in AppKernel.php file. FOSUserBundle needs a bit of configuration to make it work properly I have written a simple and easy guide on it: https://www.cloudways.com/blog/implement-fosuserbundle-in-symfony-3-1/

Installation:

composer require friendsofsymfony/user-bundle "~2.0@dev"

Enabling Bundle in AppKernel.php

After installing FOSUserBundle you must enable it in the project. Go to app/config/AppKernel.php and add the highlighted line in the bundles array.

$bundles = [
...
new FOS\UserBundle\FOSUserBundle(),
]

Create User Entity

Create the User entity as you are creating above :)

Configuring Security.yml file

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
                # 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 }

Configure FOSUserBundle in a Config

Add this config in config.yml

fos_user:
    db_driver: orm 
    firewall_name: main
    user_class: AppBundle\Entity\User

Importing Route files of FOSUserBundle

Add this to import routes in Routing.yml

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

Updating Database Schema

The last step is to update the database schema to create table in the database.

php bin/console doctrine:schema:update --force

Now move to the app URL add /login in it you will see the login page.

enter image description here