Skip to content
Tutorials Center
My learning

Topics

Symfony Tutorial

Learn Symfony 7 from your first project to routing, Twig, the service container, forms, Doctrine, security, Messenger, testing, performance and real projects. 62 lessons with examples, quizzes and projects.

Start learning →

of lessons completed

Getting Started

  1. 1 What Is Symfony? Learn what Symfony is, how the framework differs from its reusable components, how releases and LTS versions work, and how this tutorial runs its examples.
  2. 2 Installing Symfony and the CLI Install Symfony step by step: PHP requirements, Composer, the Symfony CLI, symfony new with skeleton or webapp, and the local development server.
  3. 3 Project Structure Tour every folder of a Symfony project: bin, config, public, src, templates, var and vendor, plus the .env files, composer.json and the front controller.
  4. 4 Flex, Recipes and Bundles See how composer require sets up a Symfony package for you: Flex recipes, symfony.lock, bundles vs plain packages, config/bundles.php and packs.
  5. 5 From Request to Response Follow one HTTP request through the Symfony front controller and HttpKernel, see every kernel event, and run a mini kernel stand-in to watch the lifecycle.

Routing and Controllers

  1. 6 Your First Page Build your first Symfony page: write a controller class, map a URL with the #[Route] attribute, return a Response, use make:controller and run a router stand-in.
  2. 7 Routing with Attributes Learn how the Symfony #[Route] attribute maps URLs to controllers - path, name, methods, requirements, defaults, host, priority and class-level prefixes.
  3. 8 Route Parameters and Requirements Learn Symfony route placeholders, regex requirements, optional parameters, backed enums and automatic entity loading with #[MapEntity], with a runnable router.
  4. 9 Generating URLs Learn to generate URLs from route names in Symfony with generateUrl, UrlGeneratorInterface and Twig path()/url(), including absolute URLs and query strings.
  5. 10 Controllers in Depth Understand Symfony controllers - AbstractController helpers, how arguments are resolved, controllers as services, invokable controllers and keeping actions thin.
  6. 11 The Request Object Learn the Symfony Request object - query and request bags, headers, cookies, files, attributes, JSON bodies, client IP, trusted proxies and content negotiation.
  7. 12 Responses, JSON and Redirects Learn Symfony responses - Response, JsonResponse, RedirectResponse, BinaryFileResponse and StreamedResponse, status codes, headers, cookies and caching.
  8. 13 Mapping Request Data to Objects Turn query strings and JSON bodies into typed DTO objects with #[MapQueryString] and #[MapRequestPayload], validate them, and see the mechanism in a runnable stand-in.
  9. 14 Sessions and Flash Messages Store data between requests with the Symfony session, show one-time flash messages after redirects, configure storage, and keep API routes stateless.

Templates with Twig

  1. 15 Twig Basics Learn Twig, Symfony's template engine: printing with {{ }}, tags with {% %}, comments, variables, filters, if and for, and how auto-escaping protects you.
  2. 16 Layouts, Blocks and Includes Share one page layout across your whole Symfony site with Twig template inheritance: extends, blocks, parent(), include, embed and macros, with a runnable demo.
  3. 17 Twig Functions, Filters and Tests A tour of Twig's built-in filters, functions and tests, plus Symfony's path(), url() and asset() helpers, escaping rules and loops, with a runnable evaluator.
  4. 18 Custom Twig Extensions Add your own Twig filters, functions and tests in Symfony with extensions, attributes and lazy runtime classes, then meet Twig components. Includes a runnable demo.
  5. 19 Assets, AssetMapper and Webpack Encore Ship CSS, JavaScript and images in Symfony with AssetMapper and import maps, the asset() function, Tailwind, Stimulus and Turbo, and know when Webpack Encore fits.

Services and the Container

  1. 20 Services and the Service Container Learn what a Symfony service is, how the service container creates and shares objects, how services.yaml registers them, and how to inspect them with debug:container.
  2. 21 Autowiring and Dependency Injection See how Symfony autowiring fills constructor arguments from type-hints, how interfaces and aliases choose an implementation, and build a reflection-based autowirer.
  3. 22 Configuring Services Configure Symfony services with _defaults, resource loading, bind, arguments, parameters, environment variables and autoconfigure, with a runnable parameter resolver.
  4. 23 Tags, Decorators and Service Locators Use service tags and AutowireIterator to collect services, decorate a service with AsDecorator, make services lazy, and use service locators, with runnable chain examples.
  5. 24 Compiler Passes and Bundle Extensions Understand how Symfony compiles the container, write a compiler pass and a bundle extension, and structure a reusable bundle with AbstractBundle and a config tree.

Configuration

  1. 25 Configuration and Environments Learn how Symfony loads config/packages, how dev, prod and test environments differ, how when@env works, what APP_ENV and APP_DEBUG do, and how parameters work.
  2. 26 Environment Variables and Secrets Learn how Symfony loads .env files, uses env var processors like int and json, keeps passwords in the secrets vault, and debugs where a value comes from.

Forms and Validation

  1. 27 Forms - Building and Rendering Build your first Symfony form with AbstractType and the form builder, handle the request in a controller, render it in Twig and style it with form themes.
  2. 28 Form Types and Options Tour the most useful Symfony form types (text, choice, entity, date, collection, file) and the options every field shares, plus data classes and empty_data.
  3. 29 Handling Submission and CSRF Handle Symfony form submissions correctly with isSubmitted, isValid, flash messages and redirects, show errors, and understand how CSRF protection works.
  4. 30 Advanced Forms Go beyond simple forms in Symfony with embedded forms, collections that add and remove rows, form events, data transformers and dependent dropdown fields.
  5. 31 Validation Learn the Symfony Validator component: constraint attributes, validation groups, nested objects, arrays and violations, with runnable validator stand-ins.
  6. 32 Custom Validation Constraints Build your own Symfony constraint: the Constraint class, the ConstraintValidator, validators that are services, class constraints and callbacks, with stand-ins.
  7. 33 File Uploads Handle file uploads in Symfony safely: FileType, UploadedFile, the File constraint, safe file names, moving files and Flysystem storage, with runnable stand-ins.

Databases with Doctrine

  1. 34 Doctrine ORM Setup Set up Doctrine in Symfony: install the ORM pack, write DATABASE_URL for SQLite or MySQL, create the database, meet the EntityManager and generate entities.
  2. 35 Entities and Mapping Map PHP classes to tables with Doctrine attributes: column types, identifiers, enums, embeddables and lifecycle callbacks, plus a runnable data-mapper stand-in.
  3. 36 Migrations Evolve your database safely with Doctrine Migrations: make:migration, migrate, status, rollback, schema validation and production-safe changes, with a stand-in runner.
  4. 37 Repositories and Queries Read data with Doctrine in Symfony: find methods, custom repositories, DQL, the QueryBuilder, raw DBAL and pagination, with a runnable PDO stand-in.
  5. 38 Relations Link entities with Doctrine relations: ManyToOne, OneToMany and ManyToMany, the owning side, cascade and orphanRemoval, with a runnable SQLite stand-in.
  6. 39 Doctrine Performance and Pitfalls Make Doctrine fast: spot the N+1 problem, use fetch joins, understand lazy proxies, process big tables in batches, add indexes and cache wisely.
  7. 40 Fixtures and Factories Fill your Symfony database with test data: DoctrineFixturesBundle classes, references, groups and Foundry factories, plus a runnable seeder stand-in.

Security

  1. 41 Security: Users and Firewalls Understand Symfony security: the user class, user providers, firewalls, password hashing, make:user and access_control, with runnable PHP stand-ins.
  2. 42 Login Forms and Authenticators Add logins to Symfony: form_login, json_login, custom authenticators with passports, remember me, login throttling and access tokens, with a runnable flow.
  3. 43 Authorization: Roles and Voters Decide what a signed-in user may do in Symfony: roles, access_control, #[IsGranted], role hierarchy and custom voters, with runnable stand-ins for both.

Events, Messaging and Console

  1. 44 Events and Listeners Hook into Symfony with the EventDispatcher: kernel events, listeners, subscribers, #[AsEventListener], priorities and custom events, with runnable stand-ins.
  2. 45 Messenger: Messages and Handlers Run work in the background with Symfony Messenger: messages, handlers, buses, transports, workers, retries and the failure transport, with runnable stand-ins.
  3. 46 Console Commands Write your own bin/console commands in Symfony: #[AsCommand], arguments and options, SymfonyStyle tables and progress bars, exit codes and testing, with a runnable stand-in.
  4. 47 Mailer and Notifier Send email with Symfony Mailer (DSNs, Email, TemplatedEmail, async via Messenger) and multi-channel alerts with Notifier, with runnable stand-ins for both.
  5. 48 Scheduler, Lock and Cron Jobs Run recurring work in Symfony with the Scheduler component and RecurringMessage, prevent overlapping runs with the Lock component, and compare it with plain cron.

APIs

  1. 49 Building JSON APIs Design a JSON API in Symfony: JsonResponse, honest status codes, one error format, pagination and versioning, plus a runnable mini API stand-in.
  2. 50 The Serializer Component Learn how the Symfony Serializer turns objects into JSON and back with normalizers and encoders, serialization groups and attributes, with runnable stand-ins.
  3. 51 API Platform Overview A tour of API Platform on Symfony: declare a resource, get CRUD operations, filters, pagination and OpenAPI docs, and see the idea in a runnable stand-in.

Caching, Performance and Testing

  1. 52 HTTP Caching Make Symfony responses cacheable: Cache-Control, expiration versus validation, ETag and Last-Modified, reverse proxies, with runnable cache stand-ins.
  2. 53 The Cache Component Use Symfony's Cache component: CacheInterface::get(), cache pools and adapters, expiration, tags, invalidation and stampede protection, with runnable stand-ins.
  3. 54 Testing with PHPUnit Test Symfony apps with PHPUnit: unit tests, KernelTestCase for services, WebTestCase and the client for HTTP, assertions, test database, plus a runnable test stand-in.
  4. 55 Performance and Deployment Prepare a Symfony app for production with APP_ENV=prod, cache warmup, dump-env, OPcache, preloading, FrankenPHP workers and a simple CI/CD pipeline.

Projects

  1. 56 Project: A Blog Build a Symfony blog in stages - Post and Comment entities, repository pagination, controllers, Twig templates and a comment form - with a runnable core stand-in.
  2. 57 Project: A Task Manager Build a multi-user task manager in Symfony with a User entity, firewall, voters, forms and Doctrine relations, plus runnable voter and SQLite stand-ins.
  3. 58 Project: A Bookstore JSON API Build a bookstore JSON API in Symfony with serializer groups, request payload validation, safe filtering, sorting and pagination, plus runnable stand-ins.
  4. 59 Project: Async Report Generator Build an asynchronous report generator in Symfony with a console command, a Messenger message and handler, retries, a failure transport and a mailer, with runnable stand-ins.

Practice and Review

  1. 60 Practice Exercises 15 graded Symfony practice exercises with solutions on routing, the service container, Twig, Doctrine queries, passwords, roles and CSRF, in runnable PHP stand-ins.
  2. 61 Symfony Interview Questions Prepare for a Symfony interview with clear answers on the container, kernel events, Doctrine, security, Messenger and the pitfalls interviewers love to ask about.
  3. 62 Symfony Cheat Sheet A one-page Symfony 7 cheat sheet with console commands, routing and Doctrine attributes, service, security and Messenger config, debug tools and two runnable stand-ins.