Login form
| Make the form | |
| Check credentials path | |
| Redirect on success | |
| Logout path |
Make the form
Login starts with scaffolding, not hand typing. One maker command builds the form class with the fields the checker expects.
Run it from the project root and answer the prompts. The generated class lands in the form folder, ready to render.
$ php bin/console make:form LoginFormType
created: src/Form/LoginFormType.php
Check credentials path
The firewall section names two routes: where the form shows and where it submits. Both often share one route with separate methods.
The checker reads the posted email and password itself. No controller code runs for the check path when the firewall handles it.
security: firewalls: main: form_login: login_path: app_login check_path: app_login
Redirect on success
Good logins land on a welcome page, not on raw output. The default target path names the route used after every successful login.
Add it to the same form login block. Name a real route that exists in the project, so visitors bookmark that page as their entrance.
security: firewalls: main: form_login: default_target_path: app_home
Logout path
Logout is one route and three lines: the firewall clears the session when that path opens. No action code is needed.
Link that route from the site menu. Visitors leave in one click and land back on public pages.
security: firewalls: main: logout: path: app_logout
Next: Voters
Article author: Arthur Isaev