I begin with Symfony 4 and I want to install FosUserBundle with this link : https://symfony.com/doc/master/bundles/FOSUserBundle/index.html
First :
My problem is that I don't know where to find the "app/config/config.yml" file to uncomment the translator and to configure :
fos_user:
db_driver: orm # other valid values are 'mongodb' and 'couchdb'
firewall_name: main
user_class: AppBundle\Entity\User
from_email:
address: "%mailer_user%"
sender_name: "%mailer_user%"
Second :
I think that I have to create the security.yml file in "config/packages/" directory, is that right ?
Third :
And in which file to add the route ?
Could you help me, please ? :)
I've resolved the problem followed this:
download FOSUserBundle using composer:
composer require friendsofsymfony/user-bundle "~2.0"
At the end of the installation you will have the following error message :
The child node "db_driver" at path "fos_user" must be configured.
<?php //src/Entity/User.php namespace App\Entity; use FOS\UserBundle\Model\User as BaseUser; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity * @ORM\Table(name="fos_user") */ class User extends BaseUser { /** * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="AUTO") */ protected $id; public function __construct() { parent::__construct(); // your own logic } }
security: encoders: FOS\UserBundle\Model\UserInterface: bcrypt role_hierarchy: ROLE_ADMIN: ROLE_USER ROLE_SUPER_ADMIN: ROLE_ADMIN # https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers providers: fos_userbundle: id: fos_user.user_provider.username firewalls: dev: pattern: ^/(_(profiler|wdt)|css|images|js)/ security: false main: pattern: ^/ form_login: provider: fos_userbundle csrf_token_generator: security.csrf.token_manager logout: true anonymous: true # Easy way to control access for large sections of your site # Note: Only the *first* access control that matches will be used 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 }
fos_user: db_driver: orm # other valid values are 'mongodb' and 'couchdb' firewall_name: main user_class: App\Entity\User from_email: address: "[email protected]" sender_name: "[email protected]"
Update config/packages/framework.yaml to add templating configuration
framework: templating: engines: ['twig', 'php']
fos_user: resource: "@FOSUserBundle/Resources/config/routing/all.xml"
php bin/console doctrine:database:create
Update the schema with the informations from your User class entity
php bin/console doctrine:schema:update --force
At this point, all is installed and configured to use FOSUserBundle in Symfony 4. Run the following command to check if all is ok
composer update
If you don't have any error message, you can test ! You can run the web server to test your application
php bin/console server:start
all tutorial here: https://vfac.fr/blog/how-install-fosuserbundle-with-symfony-4