Symfony4中app/config/config.yml缺失?使用FOSUserBundle配置受阻
Hey there! I totally get the confusion here—Symfony 4 overhauled its configuration structure compared to older versions (2/3), so that tutorial you’re following is likely written for the older directory setup. Let me walk you through how to adjust this for Symfony 4:
Key Change: Configuration File Location
In Symfony 4+, all bundle-specific configuration lives in the config/packages/ directory, not the old app/config/ folder. For FOSUserBundle, you’ll need to create (or edit) a file named fos_user.yaml (.yml works too) in that directory.
Step-by-Step Setup
Create the FOSUserBundle config file
Navigate toconfig/packages/and createfos_user.yamlif it doesn’t already exist (some FOSUserBundle versions generate this automatically during installation, but if not, make it manually).Add the updated configuration
Paste this into the file, adjusting values to match your setup:fos_user: db_driver: orm # Other valid options: 'mongodb' or 'couchdb' firewall_name: main user_class: App\Entity\User # Symfony 4 uses App\Entity instead of AppBundle\Entity from_email: address: '%mailer_user%' sender_name: '%mailer_user%'Note: The
user_classline is critical—Symfony 4 dropped the defaultAppBundlestructure, so your User entity should live insrc/Entity/User.phpwith the namespaceApp\Entity\User.Verify your security firewall
Make sure yourconfig/packages/security.yamlhas themainfirewall configured to use FOSUserBundle. Here’s a basic working example:security: providers: fos_userbundle: id: fos_user.user_provider.username firewalls: main: pattern: ^/ form_login: provider: fos_userbundle login_path: fos_user_security_login check_path: fos_user_security_check logout: path: fos_user_security_logout anonymous: trueSet your mailer environment variable
The%mailer_user%placeholder pulls from your root.envfile. Open.envand add/update this line:MAILER_USER=your-email@example.com
Once you’ve completed these steps, clear your Symfony cache by running php bin/console cache:clear in your terminal, and you should be ready to proceed!
内容的提问来源于stack exchange,提问作者M_Idrees

