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…
API Pagination Done Easily
…m just trying to keep
things simple.
If I were doing this in a real project, I'd probably use a library called
Pagerfanta. It helps you paginate
and has built-in adapters already for Doctrine, and Elastic Search. You can
give it things like…
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.
Customizing the Contentful Slugger
…can run:
symfony console doctrine:migrations:migrate current-1
That will reverse the most recent migration, causing the contentful and route
tables to be dropped. Put them back with:
symfony console doctrine:migrations:migrate
Re-sync the content again:
And now check the routes:
Yes…
Content Browser: Returning the Items
…web debug toolbar, we have a 400 error.
Dang. When we open that up, we see:
Value loader for doctrine_recipe value type does not exist.
There's just one final piece we need: A very simple class called the "value
loader". That's next.
Annotations to Attributes
…re back!
With just a few commands we've converted our entire site from annotations to
attributes. Woo!
Next, let's add property types to our entities. That's going to allow us to have
less entity config thanks to a new feature in Doctrine.
Entity objects in Twig
…most recent requests we've made. Here's the one we just made to
/questions/new. Click the little token string on the right to jump into the
full profiler for that request! Go to the "Doctrine" tab and... bam! Cool!
It even wraps the…
Prod Vault Optimization & Vault for Tests
…Next, let's talk about a really cool new feature called "validation auto mapping".
It's a wicked-smart feature that automatically adds validation constraints based
on your Doctrine metadata and also based on the way that your PHP code is written
in your class.
Unique (but not Insane) Filenames
…But if you want to guarantee cleaner filenames,
there's an easy way to do that. I'll use a class called Urlizer: this comes from
the gedmo/doctrine-extensions library. It has a nice method called
urlize() and we can wrap our $originalFilename in…
ManyToMany with Extra Fields
…is still there,
just the way it always was.
If you try to run this migration...it will blow up, with this rude error:
Incorrect table definition; there can be only one auto column...
It turns out, Doctrine has a bug! Gasp! The horror! Yep…
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+