Flag of Ukraine
SymfonyCasts stands united with the people of Ukraine
This tutorial has a new version, check it out!

Symfony 3: Level up with Services and the Container

33:46

What you'll be learning

// composer.json
{
    "require": {
        "php": ">=5.5.9",
        "symfony/symfony": "3.1.*", // v3.1.4
        "doctrine/orm": "^2.5", // v2.7.2
        "doctrine/doctrine-bundle": "^1.6", // 1.6.4
        "doctrine/doctrine-cache-bundle": "^1.2", // 1.3.0
        "symfony/swiftmailer-bundle": "^2.3", // v2.3.11
        "symfony/monolog-bundle": "^2.8", // 2.11.1
        "symfony/polyfill-apcu": "^1.0", // v1.2.0
        "sensio/distribution-bundle": "^5.0", // v5.0.22
        "sensio/framework-extra-bundle": "^3.0.2", // v3.0.16
        "incenteev/composer-parameter-handler": "^2.0", // v2.1.2
        "composer/package-versions-deprecated": "^1.11", // 1.11.99
        "knplabs/knp-markdown-bundle": "^1.4", // 1.4.2
        "doctrine/doctrine-migrations-bundle": "^1.1" // 1.1.1
    },
    "require-dev": {
        "sensio/generator-bundle": "^3.0", // v3.0.7
        "symfony/phpunit-bridge": "^3.0", // v3.1.3
        "nelmio/alice": "^2.1", // 2.1.4
        "doctrine/doctrine-fixtures-bundle": "^2.3" // 2.3.0
    }
}

Our app is coming to life! Thanks to the Doctrine Course we have a rich data model. And after the course on Configuration, well, using and configuring services is simple.

Now it's time to level-up with those services. These puppies are the backbone of what makes Symfony special & fast. It's also the reason that organizing your code into reusable chunks is so easy. But beyond that, once you understand how services and the service container work, you'll be absolutely unstoppable inside of Symfony. Yep, let's do that:

  • Understanding what a service is
  • Listing, fetching and using existing services
  • Creating your own custom services
  • Registering your service
  • Checking out the (mystical) dumped container
  • Configuration Parameters
  • Dependency Injection Tags

This is the episode where it all starts coming together. Let's go!


Your Guides

Ryan Weaver Leanna Pelham

Buy Access

Join the Conversation?

11
Login or Register to join the conversation
Default user avatar
Default user avatar Christian Eduardo Rivera Tello | posted 5 years ago

This course is really nice !! . I'm having fun with this course. But I have just a question, or I may say a doubt. In the Symfony Forms: Build, Render & Conquer! section , in the last video, you mentioned something like it's not good idea to bind entities with forms directlly, Instead of this, you suggested, it's better to create brand new classes( models ) to bind your forms, and then transform your models into entities with a little more code. So, I would like to know how I can perform or code this. I tried to do it by myself, however, I found with problems when I needed to validate my model( form model), using uniqueentity(this applies to the entity class ). I couldn't use this constraint in my model (form model). I'm new with symfony. Before I used laravel, and I am kind of aware of working with forms that include more than one entity; in addition, the validations are quite different. How should I do this ?. I'm trying to write good code, and use better practices. Thank you so much in advance.

61 Reply

Hi Christian Eduardo Rivera Tello!

Awesome, welcome to Symfony! Forms are one of its most powerful... but also challenging pieces! So, it sounds like you have the correct setup. Unfortunately, the UniqueEntity is one validator that suddenly will *not* work when you start using a model class like this :( - there is even an issue about it: https://github.com/symfony/....

This means that you would actually need to create your own custom validation constraint (http://symfony.com/doc/curr.... That's not a ton of work, but is definitely an unfortunate extra step. Now, when I recommended that you bind your forms to model classes instead of entities, I *only* really want you to do this when you have a complex form (i.e. a form that doesn't look like your entity). If you have a form that looks like your entity, then it's just easier to bind your form to your entity. Of course, that decision is ultimately up to you! As you can see on the linked issue, some people create model classes for all of their forms :).

Let me know if this helps! And cheers!

Reply
Default user avatar
Default user avatar Yoni L. | posted 5 years ago

YES!! got 5 offense points!! LOOL, thx for this.
This symfony 3 track is so easy to follow, very clear!!
Good job KnP guys and girls!!!

+ 5 fan points ;)

5 Reply
Default user avatar
Default user avatar Ömür Yanıkoğlu | posted 5 years ago

Please hurry up :)

Reply

Ok, we did :p. This is up now!

1 Reply
Default user avatar
Default user avatar Ömür Yanıkoğlu | weaverryan | posted 5 years ago

You rock! Thank you so much :)

Reply

I went ahead and added my comment to step 9.1 yet ill drop it here too just in case.

Hey there there

Are there any plans to delve deeper into this topic? (SOA in symfony) ? It was a wonderful topic, yet we just scratched the surface and it felt a VERY important topic to master.

It seems to me this whole area should be explored and explained a bit more deeply, maybe its just me, but it fascinated me, breathtakingly amazing thing to learn and master, I for one, want more, more in-depth learning of this topic.

Reply
Default user avatar
Default user avatar samir Patel | posted 5 years ago

I loved this course! Learned so much new and cool stuff. I especially love the keyboard shortcut for type-hinted constructor arguments. Symfony rocks!!!

Reply

is there an estimated date for this tutorial ?

Reply

Today! Sorry for the late reply, but at least it's good news ;).

Reply

hahaha, yeah at least it's great news

Reply
Cat in space

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

userVoice