Login form

Contents
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

Related articles
Development with PHP
What is Symfony and where it runs
Install Symfony
Your first page
Routes
Controllers
Twig basics
Twig advanced
Doctrine setup
Entities
Migrations
Repositories
Relations
Forms
Validation
Services and DI
JSON controllers
Serializer
Security intro
Users
Login form
Voters
Console commands
Events
Messenger
Mailer
Cache
Sessions
CSRF
Translations
Dotenv and env
Profiler
Testing
Fixtures
Pagination
File uploads
API Platform in one lesson
DQL
Transactions
Migrations advanced
Security advanced
HTTP client
Scheduler
Webhooks
Asset Mapper
Deployment
Performance
Capstone: blog
Capstone: JSON API
Modern Symfony tour
Hero roadmap: the whole course on one page
Banner image

Search this site

Channel @aofeed Chat @aofeedchat

Contacts and cooperation:
I recommend our hosting beget.com
Write to info@aredel.com if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: