Flag of Ukraine
SymfonyCasts stands united with the people of Ukraine

Harmonious Development with Symfony 6

2:23:48

What you'll be learning

// composer.json
{
    "require": {
        "php": ">=8.0.2",
        "ext-ctype": "*",
        "ext-iconv": "*",
        "symfony/asset": "6.0.*", // v6.0.3
        "symfony/console": "6.0.*", // v6.0.3
        "symfony/dotenv": "6.0.*", // v6.0.3
        "symfony/flex": "^2", // v2.1.5
        "symfony/framework-bundle": "6.0.*", // v6.0.4
        "symfony/monolog-bundle": "^3.0", // v3.7.1
        "symfony/runtime": "6.0.*", // v6.0.3
        "symfony/twig-bundle": "6.0.*", // v6.0.3
        "symfony/ux-turbo": "^2.0", // v2.0.1
        "symfony/webpack-encore-bundle": "^1.13", // v1.13.2
        "symfony/yaml": "6.0.*", // v6.0.3
        "twig/extra-bundle": "^2.12|^3.0", // v3.3.8
        "twig/twig": "^2.12|^3.0" // v3.3.8
    },
    "require-dev": {
        "symfony/debug-bundle": "6.0.*", // v6.0.3
        "symfony/stopwatch": "6.0.*", // v6.0.3
        "symfony/web-profiler-bundle": "6.0.*" // v6.0.3
    }
}

Woh, it's Symfony 6 time! The best, smoothest and most enjoyable version of Symfony yet, whether you're building an API or a slick JavaScript-driven frontend. Oh, and it's also the first version of Symfony that was made entirely for PHP 8.

Symfony 6 is all about streamlining your development experience, putting solutions and your fingertips and helping you enjoy the process. Because, done correctly, programming is a BLAST.

On your marks, get set, code!

  • Create a fancy new (but tiny!) Symfony app that will make your friends proud
  • Install & explore the symfony binary for development tricks
  • Prep PhpStorm & plugins for the BEST experience
  • Learn about Symfony Flex & the "recipes" system
  • Install 3rd party packages and bundles
  • Create routes and controllers (with PHP 8 attributes!)
  • The bin/console tool
  • Twig & templating
  • The web debug toolbar: insane debugging at your fingertips
  • JavaScript & Asset Setup with Encore & Symfony UX
  • Create a JSON API endpoint & calling via Ajax
  • A peek into the most important part of Symfony: services!

Let's go friends!


Your Guides

Ryan Weaver


Join the Conversation?

26
Login or Register to join the conversation
Nizar Avatar

Hello,

could you put tutorials about elastic search and Symfony?
it is in high demand in the job market

3 Reply
Yangzhi Avatar
Yangzhi Avatar Yangzhi | posted 1 year ago

can not wait anymore

3 Reply

no one can ;) stay tuned!

Reply
Salvadorrueda Avatar
Salvadorrueda Avatar Salvadorrueda | posted 1 year ago

Awesome content. Thanks for sharing. Time to put it in practice.

2 Reply
Ruslan Avatar

Hi Ryan,
Could you make a course about testing? (Codeception).
Thank you.

2 Reply

Hey Ruslan!

Thank you for your interest in SymfonyCasts tutorials! We don't have any certain plans to cover Codeception in the nearest future unfortunately, but I add this topic to ours idea pool, thanks! Also, we're planning to brush up our tutorials about testing, i.e. PHPUnit, PhpSpec and Behat - most probably it will happen in 2022, but no any possible release date yet too. Meanwhile, in case you're interested in Testing tools, I'd recommend you to take a look at Testing track: https://symfonycasts.com/tr...

Cheers!

Reply
Ruslan Avatar

Thank you.
But if you will update "Testing tutorials", don't forget about Stimulus too, please.

1 Reply

Hey @Ruslan!

We’re definitely planning by on a big testing update - we need it!

About Stimulus - no update is needed there. Stimulus 3 is out, but other than a renamed package name and a few minor features, it is identical to v2. But if the tutorial is not making this fact obvious enough, please let me know!

Cheers!

1 Reply
Ruslan Avatar

I mean tests for App with Stimulus.

1 Reply

We will definitely be talking about that in those tutorials :)

1 Reply
JesusCH Avatar
JesusCH Avatar JesusCH | posted 1 month ago

Ha sido un tutorial básico, practico y muy explicado.

Reply

Hola @JesusCH

Nos da gusto saber que te ha sido util nuestro tutorial

Saludos!

1 Reply
Anthony-E Avatar
Anthony-E Avatar Anthony-E | posted 1 month ago

Hi There, I know that when we have a WordPress website, there are a lot of updates to manage every week. How does that exactly work with Symfony ? Is the pace of updates slower like a little change of syntax once in while or some new features added here and there that don't really mess with the existing features ?

Reply

Hey Anthony,

Yeah, code evolves a lot during the time that leads to new features and updates, i.e. led to continuous maintenance of the project. Well, I'm not aware of WordPress policy too much, but I probably may shed some light on Symfony's development process.

Well, first of all, except Symfony you most probably will have other third-party dependencies, i.e. packages that evolve on their own... I suppose in WordPress it's the same thing, even if we will consider additional plugins that might be installed in your project and also do some updates. So, if we will set aside those 3rd-party libs and focus only on Symfony - here's what we have.

Symfony has a so-called backward compatibility (BC) promise - you can learn more about it here: https://symfony.com/doc/current/contributing/code/bc.html - mostly it means that BC breaks may happen only during the major Symfony upgrades, e.g. from Symfony 5 -> Symfony 6. If you just want to upgrade a minor version, e.g. from Symfony 5.2 -> 5.4 - there should not be any BC breaks and your project should work well after the upgrade without any required changes. Well, in practice, it may not be 100% true, but it mostly depends on how well you're writing your code, or if you're using experimental components or not. So, such minor version updates will bring you new features as also some security fixes, etc, but they should not break your code base in theory.

Now about the Symfony roadmap (schedule of releases) - you can see more here: https://symfony.com/releases . As you can see Symfony has LTS (Long-Term Support) Release which means you don't have to update your major version if you don't want (don't need new features they may give you) and still get those important bugs and security fixes. LTS versions live for 3 years of maintenance + 1 extra year of only security fixes. If you have a big and complex project and don't want to upgrade it too often because it's time-consuming for you or just because you don't need those new features - stick to the LTS version :) The new LTS version is created every 2 years as you can see from the schedule.

So, that's basically it, that's how Symfony works, and that's what its release schedule and promises. Mostly, it's a similar process to the Ubuntu release cycle if you're aware of it. But it's up to you to decide if that fits your needs or not and how much load it will put on you to maintain it.

I hope this helps! :)

Cheers!

1 Reply
Yukako Avatar
Yukako Avatar Yukako | posted 2 months ago | edited

Hi all, I am running symfony 6 and cannot see the Debug Toolbar anymore. Only when I get an Error or warning it appears...
Please heeeeelp ! I get mad :(

when@dev:

web_profiler:
    toolbar: true
    intercept_redirects: false

framework:
    profiler: { only_exceptions: false }
Reply

Hello @Yukako,

Do you have twig installed? and normal template for testing?

Cheers!

Reply
Miracle Avatar

Awesome content

Reply

Hey Miracle,

Thank you for your feedback! We're happy to hear you liked it :) See more Symfony 6 related courses in this track: https://symfonycasts.com/tracks/symfony

Cheers!

Reply
Anthony-E Avatar
Anthony-E Avatar Anthony-E | posted 2 months ago

Hi, I wish there was a tutorial about deploying to platform.sh (apparently the recommended hosting service).

Reply

Hey @Anthony-E!

Sorry for the slow reply! It's something I'd like to do too - I'll add a vote for it on our internal tracker. If you'd like to see an example of a site deployed with platform.sh, you can see https://github.com/symfony/ux/tree/2.x/ux.symfony.com

Cheers!

Reply
montecarlocode Avatar
montecarlocode Avatar montecarlocode | posted 4 months ago

Awesome course. I figured out symfony's power.

Reply

Woo! Keep up the good work 💪

Reply
Default user avatar

U type param string $slug = null, I think better way is to type like this ?string $slug = null, or string $slug = '', bacause '' == null but '' === null is not true.

Reply
Tom O. Avatar
Tom O. Avatar Tom O. | posted 1 year ago | edited

I am dynamically generating forms in Symfony 6. From the controller, I am calling a Form Type class in the traditional method. Therein, I am dynamically building some form fields based on the elements of the $options passed to the FormType class.

    public function index(Request $request): Response
    {
    // Entity is called Breed
    $data = new Breed();

    // I am passing these $options to the form
    $options = [
            'form_1'          => true,
            'form_2'          => false,
            'units'           => 'pounds'
            'form_3'          => false,
        ];

    $form = $this->createForm(BreedSurveyType::class, $data, $options);

In the BreedSurveyType form class, I am able to get my variables where I declare them in the configureOptions() method...

 public function configureOptions(OptionsResolver $resolver): void
    {
        $resolver->setDefaults([
            'data_class' => Breed::class,
            'form_1'          => false,
            'form_2'          => false,
            'units'              => null
            'form_3'          => false,
        ]);
    }

In the buildForm() method, I can access the $options, but I cannot if I embed a sub-form.

 public function buildForm(FormBuilderInterface $builder,array $options): void 
{
        // form_1          =   true
        // form_2          =   false
        // units           =  'pounds'
        // form_3          =   true

        if ($options['form_1'] === true) {
            $builder->add(
                    'name',
                    AnimalNameType::class
                );
        }

        if ($options['form_2'] === true) {
            $builder->add(
                    'sex',
                    AnimalSexType::class
                );
        }

        if ($options['form_3'] === true) {
            $builder->add(
                    'weight',
                    AnimalWeightType::class
                );
        }

.... in the parent-form, when I dump the $options variable,

array:59 [▼
  // snippet from web debug toolbar
  "form_1" => true
  "form_2" => false
  "units"  => "pounds"
  "form_3" => true
]

.... in the sub-form, when I dump the $options variable, I get the results from the declarations I made in the configureOptions() method.

array:59 [▼
  // snippet from web debug toolbar
  "form_1" => false
  "form_2" => false
  "units"  => null
  "form_3" => false
]

Effectively, is there a method to pass $options to a subform or do I need to isolate my logic of the dynamically created form in my BreedSurveyType class?

Thank you in advance.

Reply

Hey Tom O. !

Ah, I think I understand. By "sub form", you are referring to the AnimalNameType and other Animal###Type classes, right? If you want to pass options into those, you need to do it manually via the 3rd argument to ->add() For example. Suppose that you need to pass the units option into a sub-form:


public function buildForm(FormBuilderInterface $builder, array $options): void
{
    if ($options['form_1'] === true) {
        $builder->add(
            'name',
            AnimalNameType::class,
            ['units' => $options['units']]
        );
    }

    // ...
}

Of course, you'll need to make sure that AnimalNameType allows a units option in its configureOptions() method, but it sounds like you already have that.

Is that what you were referring to? If I completely missed the point, let me know :).

Cheers!

Reply
Cat in space

"Houston: no signs of life"
Start the conversation!

userVoice