Symfony Messenger: 6 months already and more to come
…Actually, who here is
actually is using Doctrine? I was expecting more people. So half of the room
actually admit they use Doctrine. So the idea is simple: you've got a database
URL in Doctrine, so you can configure whether it's MySQL or…
Request Object & Query OR Logic
…places. One mistake could lead to an OR causing many more results
to be returned than you expect!
To best handle this in Doctrine, always use andWhere() and put all the OR logic
right inside: c.content LIKE :term OR c.authorName LIKE :term. On…
Query Joins & Solving the N+1 Problem
…make sense anymore? I mean, if we're already making a
JOIN to the article table, isn't this extra query unnecessary? Doesn't Doctrine
already have all the data it needs from the first query, thanks to the join?
The answer is... no, or…
ManyToMany Relationship
…owning versus inverse stuff is important because, when Doctrine
saves an entity, it only looks at the owning side of the relationship to figure
out what to save to the database. So, if we add tags to an article, Doctrine will
save that correctly. But…
The Twig Extensions Library
…actually, a better question is: should
we solve this? Here's the point: you need to be aware of the fact that Doctrine's
nice relationship lazy-loading magic makes it easy to accidentally make many queries
on a page. But, it is not something…
Fun with Commands
…if you needed your SlackClient service,
you would just add a __construct() method and autowire it!
With our new knowledge, let's keep going and start mastering features, like the
Doctrine ORM, form system, API stuff and a lot more.
Alright guys, seeya next time…
Services
…you learn to master services, you can do anything from
anywhere in Symfony.
There's a lot more to say about the topic of services, and so many other parts
of Symfony: configuration, Doctrine & the database, forms, Security and APIs, to
just name a few…
Exceptions Part 2: Adding Fence Security
…Actually, I don't need
to refactor, but now is a great time to add the missing Doctrine annotations.
Above the $securities property, add @ORM\OneToMany() with targetEntity="Security"
and mappedBy="enclosure". enclosure is the name of the property on the other
side of the…
Rock some FOSUserBundle!
…php bin/console
It's alive! Now, we can generate the migration for our User class:
php bin/console doctrine:migrations:diff
Yep, that looks about right. Run it:
php bin/console doctrine:migrations:migrate
Perfect!
At this point, the only thing this bundle has…
The POST Create API
…just
simpler if you can update the state immediately.
And that is why UUID's can be awesome. If you configure your Doctrine entities to
use UUID's instead of auto-increment ids, you can generate valid UUID's in JavaScript,
update the state immediately…
Give the User a Subscription (in our Database)
…and $stripeSubscription->id:
Booya!
And, time to save this to the database! Since we're using Doctrine in Symfony, we
need the EntityManager object to do this. I'll use dependency injection: add an
EntityManager argument to the __construct() method, and set it on a…
Finishing with kernel.response and kernel.exception
…After that, the
controller is called and the stuff under that is our work. We can see
some Doctrine calls we’re making and the time it takes to render the template.
After the controller, the kernel.response event is dispatched, it has
a few…
Twig Extensions and Dependency Injection Tags
…to unlocking really powerful features.
A very important tag is kernel.event_listener, which allows you to register
“hooks” inside Symfony at various stages of the request lifecycle. That topic
is for another screencast, but we’ll cover a very similar subject next: Doctrine
events.
Blog
Doctrine's HIDDEN gem
We had a great question from a user recently where the answer involved a
little-known Doctrine feature called HIDDEN. You won't need it often,
but it deserves its 5 in the spotlight!
HIDDEN allows you to select a field so that you can…
|
doctrine: |
|
|
// ... lines 2 - 7
|
|
orm: |
|
|
// ... lines 9 - 18
|
|
filters: |
|
fortuneCookie_discontinued: App\Doctrine\DiscontinuedFilter |
|
|
// ... lines 21 - 47
|
See Code Block in Script
|
doctrine: |
|
|
// ... lines 2 - 7
|
|
orm: |
|
|
// ... lines 9 - 18
|
|
filters: |
|
fortuneCookie_discontinued: |
|
class: App\Doctrine\DiscontinuedFilter |
|
enabled: true |
|
parameters: |
|
discontinued: false |
|
|
// ... lines 25 - 51
|
See Code Block in Script
x
1000+