> Symfony 4 >

Course Overview

Stellar Development with Symfony 4

  • 7076 students
  • EN Captions
  • EN Script
  • Certificate of Completion

Your Guides

About this course

What PHP libraries does this tutorial use?

// composer.json
{
    "require": {
        "php": "^7.1.3",
        "ext-iconv": "*",
        "sensio/framework-extra-bundle": "^5.1", // v5.1.3
        "symfony/asset": "^4.0", // v4.0.3
        "symfony/console": "^4.0", // v4.0.14
        "symfony/flex": "^1.0", // v1.17.6
        "symfony/framework-bundle": "^4.0", // v4.0.14
        "symfony/lts": "^4@dev", // dev-master
        "symfony/twig-bundle": "^4.0", // v4.0.3
        "symfony/web-server-bundle": "^4.0", // v4.0.3
        "symfony/yaml": "^4.0" // v4.0.14
    },
    "require-dev": {
        "easycorp/easy-log-handler": "^1.0.2", // v1.0.4
        "sensiolabs/security-checker": "^5.0", // v5.0.3
        "symfony/debug-bundle": "^3.3|^4.0", // v4.0.3
        "symfony/dotenv": "^4.0", // v4.0.14
        "symfony/monolog-bundle": "^3.0", // v3.1.2
        "symfony/phpunit-bridge": "^3.3|^4.0", // v4.0.3
        "symfony/profiler-pack": "^1.0", // v1.0.3
        "symfony/var-dumper": "^3.3|^4.0" // v4.0.3
    }
}

Symfony 4 is out! And it's the best Symfony ever! Faster! Re-imagined developer experience! And easier to create the feature you need!

So let's start coding already!

  • Setup your new (tiny) Symfony app
  • PhpStorm setup for a killer experience
  • Flex & understanding recipes
  • Creating routes and controllers
  • The bin/console tool
  • Twig & templating
  • Crazy-good debugging with the web debug toolbar
  • JavaScript & Asset Setup
  • Our first API Endpoint!
  • An intro to.... services!

Upgrading to Symfony 4? See Upgrade to Symfony4 and Flex!

Next courses in the Symfony 4: Blast Off! (beginner) section of the Symfony 4 Track!

82 Comments

Sort By
Login or Register to join the conversation
Default user avatar Mohammed Zayan 5 years ago

I fall in love with Symfony

12 | Reply |

Symfony is an amazing framework, its entirely worth investing your time into learning it! the learning curve can be a bit step, but once you get the hang of it, it turns into the easiest and most fun framework to work with ever.

2 | Reply |

Hey jlchafardet

You are correct :) once you understand how Symfony works, then you can do your work "x" times faster and better
Oh, and you can speed up the learning curve if you follow up our tutorials ;)

Cheers!

4 | Reply |
Default user avatar Vince Liem 5 years ago

Pffft not so sure if http://www.phpbenchmarks.com is completely unbiased. The creator of that site has a github that is very affiliated with Symfony. But nonetheless, EVEN IF symfony's performance benchmark is questionable. Your courses will undoubtedly score gold medals in every aspect including helpful, educational and entertaining. Keep it up! <3 knp University.

7 | Reply |

Hey Vince,

Haha, well, all the code which is tested on that website are open-source, so you can check what exactly is tested on GitHub ;)

Thanks for the kind words about KnpU! They make us moving forward and release more awesome content :)

Cheers!

1 | Reply |
Ad F. avatar Ad F. 5 years ago

can you include Symfony Security ? login ... registration

3 | Reply |
Kribo avatar Kribo 5 years ago

OK I got a question for knp uni in general...
-- Where do we ask general questions -- non tutorial questions -- Is there a Q&A section on the website I haven't found yet ?---
Questions like .... eeeu ... oyeah .. How do we earn Sensiolab badges? for ex.

Where's the knp uni suggestion box ??

2 | Reply |

Hey Kribo,

You can ask related questions in comments section below a video that relates to your question.

You can also ask questions by contacting us via email, here's our contact form: https://symfonycasts.com/co...

If you have any suggestions, we do have a suggestion box too, look for "Ideas or Feedback?" button in the right bottom corner of each page.

I hope this helps.

Cheers!

1 | Reply |
Thomas W. avatar Thomas W. 4 years ago

I'm wanting to sharpen my skills on Symfony.
Problem is: Drupal 8 is not on Symfony 4.
And the symfony 3 tutorials are not accurate - (e.g., the directories advertised are not correct.

Advice?

1 | Reply |

Hey T. Wagner,

What do you mean that our Symfony 3 tutorials are not correct? Did you download the course code or started a new project from scratch downloading a fresh version of Symfony?

Cheers!

| Reply |
Abelardo avatar Abelardo 5 years ago

Hi everyone!

Why don't I see all videos tagged as completed???

I watched all of them. ¿?

Any help would be welcome!

Regards. Nice tutorial.

1 | Reply |

Hey AbelardoLG,

We're sorry about that. Please, contact us directly via our contact form: https://symfonycasts.com/co... so that we know your email, and I'll check it for you.

Cheers!

2 | Reply |
Default user avatar Gerver 5 years ago

Greetings KnpUniversity,

After finishing this course, I've been stuck with the thoughts of possible ways i could approach a flat php project, in order to convert this to a Symfony 4 project. There for I have a question.. I have been searching for awhile now and I haven't quite found a best approach that's actualy up to date with Symfony 4 but:

What would be the best recomendations/approach towards migrating a [big] flat PHP project (5.6) to Symfony 4? (Steps i should consider/ or a point in the direction)
(In this project: has a login feature, in work with XPath to return te correct url(or functions) which the user has permission to use or access) It is a pretty big project en require quite some js files and other pages to work as a whole.

Not sure if i'm allowed to ask this question here but, maybe others would also like to know a general approach towards such task or steps they should consider.

Kind regards,
Gerver

1 | Reply |

Hey Gerver,

It's a complex question, and the answer depends. Well, refactoring is always a pain, but migrating from one framework to another is much painful. Are you actively developing the project? Working on new features? If not, then it probably would be a bit easier to migrate your project to Symfony, you can actively start migrating it and when you're done - you will just replace the old project with the new one. But if you're actively coding new features on your current project - that's much difficult, because you will need to code that feature in both projects. There're a few tricks, you can start sharing services (that actually are just PHP classes) between projects, then you'll need to teach your autoloaders load those classes and write only configuration, its implementation probably remains the same, especially if you're using a lot of Symfony components in your project. If not, then it's a good idea to start using more and more Symfony components and refactoring your custom implementation in favor of Symfony components first - it'll help you migrating easier. Then, just postpone to write *everything* in Symfony way, i.e. keep hardcoded HTML forms, do not use Doctrine ORM, keep plain queries with PDO, etc. When you finish migrating to Symfony, it would be easier to refactoring these things to Symfony Forms, Doctrine ORM, etc - you can start with simple forms, start using ORM for simple entities that have no or little relations to others. But there's no simple solution, anyway you'll need to do a lot of work, but probably the main task is do not messed it up and do not get lost in refactoring. And of course, write a lot of tests! Test everything, and discover broken tests on the first stage.

I hope this helps.

Cheers!

1 | Reply |
Default user avatar Davide Valguarnera 5 years ago

"The media could not be loaded", are there problems with videos files?

1 | Reply |

Hey Davide Valguarnera ! Hmm I'm not getting that same error, can you send me some additional details on: (a) which specific video are you having trouble watching and (b) browser/operating system you're running?

1 | Reply |
Default user avatar Davide Valguarnera leannapelham 5 years ago

All videos, window 7 64bit, firefox quantum

1 | Reply |

Hey Davide Valguarnera

Could you tell us if you can see any other error messages? (maybe in the developer's console tab)

I'm on Windows 7 + Firefox too, and I can't reproduce that behaviour. Do you have the latest version of Firefox installed? or maybe you have a weird extension installed causing connectivity problems?

Could you try to watch our videos in any other browser, just to be sure that is something related to Firefox. Thanks!

Cheers!

| Reply |
Default user avatar Davide Valguarnera MolloKhan 5 years ago edited

Thanks for yours quick answers MolloKhan MolloKhan

player on firefox : https://i.imgur.com/vyOW4S0...

player on chrome : https://i.imgur.com/txYZRZ8...

dev console screen : https://i.imgur.com/LcEMJGH...

Dev console text :

Il caricamento HTTP non è riuscito con stato 403. Impossibile completare il caricamento della risorsa multimediale https://player.vimeo.com/ex.... micro-app-phpstorm

(italian text cause italian browser, I guess you can easely understand is a 403 http error from vimeo player)

Object { code: 4, message: "The media could not be loaded, either because the server or network failed or because the format is not supported." }

VIDEOJS: ERROR: (CODE:4 MEDIA_ERR_SRC_NOT_SUPPORTED) The media could not be loaded, either because the server or network failed or because the format is not supported. video-4659f5f72fd827496a39.js:1:20993

L’utilizzo di getPreventDefault() è deprecato. Al suo posto utilizzare defaultPrevented.

(and the typical preventdefault warning)

That's all there is in my console (I tried also to disable uBlock thinking it could be related to ads before video but nope)

| Reply |

Hey Davide Valguarnera

Don't worry about the italian text, I can get a bit of italian :) (because I'm a spanish speaker)

This is very interesting, I'm using the same OS and browser than you, and I don't get any errors...
Do you have problems watching videos in any other sites? maybe a video directly from Vimeo's
Can you try opening this video: https://player.vimeo.com/ex...

I was hoping that it was a temporary problem from Vimeo, but you are having this problem today too, right?

| Reply |
Default user avatar Davide Valguarnera MolloKhan 5 years ago edited

MolloKhan It seems it was actually temporary, cause today after login today videos started playing correctly.

| Reply |

Phew! I'm super happy to hear that
If you ever have this problem again, don't hesitate to contact us

Cheers!

| Reply |
Default user avatar ROHIT SAGAR 4 years ago

I have just learnt the fundamentals of Symfony and seriously i am in love with this framework. Thank for making Symfony.

| Reply |

Hey Rohit!

Thank you for your feedback! That's awesome to hear for us! And that's our main purpose, explain complex things in simple words, though the more you learn about Symfony - the more you understand that the idea behind of it is simple (and awesome) from the developer's perspective ;)

Cheers!

| Reply |
Yukako avatar Yukako 4 years ago

Hello, I urgently need advice, otherwise I jump out of the window :)
I have done my redirection to HTTPS as follows :

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%%{SERVER_NAME}/$1 [R=301,L]
FallbackResource /index.php

He comes to the first page via HTTPS, but loads a little further and then the page breaks off.
with ERR_CONNECTION_CLOSED (On Mobile and PAD)

my page http://tscone.com

Logevel's on debug, but I can't find anything inconspicuous.

Symfony 4.x

Thank you !

Translated with www.DeepL.com/Translator

| Reply |

Hi Yukako!

Sorry for never replying - your comment got marked in spam (I think it was the translation link on the bottom). I hope you figured out your issue!

Cheers!

| Reply |
Default user avatar Alain Holler 5 years ago

Hi, I have a problem.

I don't know what these lines mean:
"Some files may have been created or updated to configure your new
packages. Please review, edit and commit them: these files are yours."

I typed in "composer require server" just according to the second video of this tutorial.

Can u help me? I'd greatly appreciate it, since it's very important for my study.
Please explain easy.

I use Windows.

| Reply |

Hey Alain Holler

Unfortunately I cannot reproduce your error, I'm on Windows too, maybe you can give us more details about it?
By the way try to run "composer install" or "composer update" and after retry to require server

I hope this helps.

Cheers!

| Reply |

Hey sadikoff!

Ah, I don't think this is an error at all! Actually, this is great! You're seeing this message:

> Some files may have been created or updated to configure your new packages. Please review, edit and commit them: these files are yours.

This is the "recipe" system in action :). You can learn all about that very important system in this chapter: https://symfonycasts.com/sc...

I hope that helps!

Cheers!

| Reply |

hey there its been a while! how are things going? I'm really glad for the changes in the community and the current direct line of communication and work with symfony, you are doing a great job and I hope things keep getting better.

I have a question, is there any way to process forms "without" rendering forms using the component? what I mean is, get my own form, yet get it processed by the component.

instead of defining the fields in the controller/form template, I just render my personalized, stylized form, and when processing the post, use the form component to either validate and or process it?

| Reply |

Hey jlchafardet!

Nice to hear from you again! We're keeping busy as you've noticed ;). But, we're super excited - thanks for the nice words :).

Interesting question. And yea, totally! It's quite easy :). Here's basically what you do:

A) Create your form - and name your fields however you want.
B) Your controller code (for processing the submit) will look a little bit different. Instead of using $form->handleRequest(), you'll fetch the data manually and use a different method. Something like this:


public function newThing(Request $request)
{
    if ($request->isMethod('POST')) {
        $form = $this->createForm(...);
        $form->submit([
            // here, manually pass all the data you need - they keys should match up with the fields you added to your form class
            // you could also cheat and use $request->request->all() to get all POST fields
           'firstName' => $request->request->get('firstName'),
        ]);

        if (!$form->isValid()) {
            // this is probably the trickiest part. $form->getErrors() will return a FormErrorIterator object (an object you can foreach over)
            // that contains 0 to many FormError objects. You need to process these (more on that below) and render the error in the template
        }
    }
}

So, it's pretty simple - just pass the data you want to $form->submit(). The tricky part is handling the errors. I started to talk about that above. The tricky thing is that $form->getErrors() does not return what you expect. I would expect an associative array of all of the errors on the form - where the key matches the name of each field. But actually, you need to collect the errors with code like this: https://gist.github.com/weaverryan/2f9dacb4c996c9b9badf - because each field is is own Form object. It's... a bit confusing I admit :).

Oh, also don't forget to handle CSRF protection. By default, you form objects will expect it. An easy way to handle this is to set a csrf_token_id option on your form class - e.g. to "my_cool_form". Then, render a hidden field manually with:


&lt;input type="hidden" name="_token" value="{{ csrf_token('my_cool_form') }}" /&gt;

Then you will be rendering the CSRF token that the form is expecting.

Phew! I hope this helps! Cheers!

1 | Reply |

I'm glad youve been keeping busy and improving the site! hope its success grows exponentially now, its indeed by all means a great resource site for those wanting to learn! I've learnt a lot from it and benefited much, I'm certain thousands of others would feel the same, congrats!

I'll take a look! and experiment a bit, I know I can access the request->request->get method, I was wondering if there was a way to make it less crumble-some, using the $form->handleRequest and $form->getData but if not not a problem haha

22 | Reply |
Aleksandr T. avatar Aleksandr T. 5 years ago

Hello!
have you a lesson with create symfony 4 authentication page?

| Reply |

Hey Aleksandr T. ,

Not yet, but we have it on our TODO list, so we'll release it soon anyway, but I don't have any estimations yet, because right now we're releasing ReactJS course. You can follow the progress on the course overview page: https://knpuniversity.com/s... - you can subscribe for notifications and we'll email you when it is started releasing. If you don't want to wait, you can check our security tutorial for Symfony 3 project: https://knpuniversity.com/s... - if you have any problems applying it on Symfony 4 - just leave a comment below the video and we'll help you to figure out the problem.

Cheers!

| Reply |

find replay in order comments))

| Reply |
Default user avatar Aamir 5 years ago edited

there Thank you for the symfony4 tutorial. It's awesome. Can you please add a video on how to use forms in symfony4. Thank you.

| Reply |

Hey Aamir,

Nothing much were changed in Symfony Form, so you can start with our Symfony 3 Forms course: https://knpuniversity.com/s... and if you have any problems - just leave us a comment below the video and we'll help you. Of course, you need to require symfony/form component with Composer at first since Symfony 4 is small and don't have this dependency by default.

Cheers!

1 | Reply |

when can we expect this course

| Reply |

Hey John,

As you can see this course is been already releasing right now: 2 chapters were already published recently. So we're going to release it completely in a few weeks, but new chapters will be published one by one during this time.

Cheers!

| Reply |

Are there any plans on adding testing to this course? I've already started playing with Sumfony4 and am loving it, but having issues with testing and DB

| Reply |

Hey railto!

We won't cover testing in *this* tutorial specifically. But, what issues are you having? How can we help? One gotcha currently (I say currently because I would very much like to change it) is that in phpunit, the environment variables are read from phpunit.xml.dist instead of .env (.env is not read at all). Mentioning that because... it could be your issue ;).

Cheers!

1 | Reply |

Hey weaverryan, sorry for taking so long to get back. The main issue im having is that I want to use an in memory sqlite db for testing. I need to figure out how I can run my doctrine migrations as part of the tests.

| Reply |

Hey Mark,

Hm, that's a bit pointless, since migrations are written for a specific SQL server like MySQL, SQLite, etc. That's why you can see this line in migration:
$this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.');

So if you use MySQL in production but SQLite for testing - you probably won't be able to do so. But if you use the same environment - great, then you can easily run migrations instead of creating an empty schema on your CI server and if it passes - then probably everything is OK (at least you don't have any syntax errors, maybe just logical ones :) ). So the idea is that you may make running migrations as a part of your CI when building your project.

I hope this helps

Cheers!

| Reply |

Never even noticed that line before.

That puts me in a really tough place then with regards to testing, I use CodeShip for my CI and the DB details are passed as vars, but in symfony 4 the db is connected via dsn, not sure how I can pull that through then

1 | Reply |

Hey railto

Have you tried this bundle? LiipFunctionalTestBundle, it allows you to use SQLite for your testing environment (besides other things like running fixtures). I believe it can help you through your problem

Oh, and we have a tutorial about TDD in case you are interested: https://knpuniversity.com/s...

Cheers!

| Reply |
Default user avatar Eduardo Guglielmotti 5 years ago

KnpPaginatorBundle is compatible to use in Symfony 4?

| Reply |

Hey Eduardo Guglielmotti

Nice question! Actually I had to do some research and I found that they added support for Symfony 4 since last year! https://github.com/KnpLabs/...

Cheers!

| Reply |
Default user avatar Eduardo Guglielmotti MolloKhan 5 years ago

I have looked at the link you sent me but I do not clarify much
Is it installed with composer like in Symfony 3? or you have to do something special, because that I have not seen

regards

| Reply |

Yes, you can install it with composer, but I believe it won't come with a recipe, so if that's the case you will have to configure it as you would do it in Symfony3, actually we have a video teaching how to handle bundles that does not have a recipe yet: https://knpuniversity.com/s...

I hope it helps :). Cheers!

| Reply |
Default user avatar Eduardo Guglielmotti MolloKhan 5 years ago

Ok thank you, I try it and then I comment the results

1 | Reply |

Delete comment?

Share this comment

astronaut with balloons in space

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