Binding Forms to Objects: data_class
…Look at this! A free drop-down with almost no work. It also noticed that isPublished
should be a checkbox because that's a boolean field in Doctrine:
And since firstDiscoveredAt is a date, it rendered it with year-month-day drop-down
boxes. Now…
Custom Query in EntityType
…So, if you pass a query_builder option and set it to an anonymous function, Doctrine
will pass that the entity repository for this specific entity. All we need to do
is create whatever query builder we want and return it.
In the form, add…
The All-Important User Class
…somewhere else - like a central authentication server. In those cases,
you will still have a User class, you just won't store it with Doctrine.
More on that as we go along.
Ok, we've got the empty user class: let's fill it in!
The UserInterface Methods (Keep some Blank!)
…feel ok leaving these blank.
So in our application, we want to store users in the database. So let's set this
class up with Doctrine. Copy the use statement from SubFamily and paste it here:
Next, I'll put my cursor inside the class…
Users Need Passwords (plainPassword)
…plain-text password on the User and encode it automatically
via a Doctrine listener when it saves.
To do that, add a new property on User called plainPassword. But wait! Don't
persist this with Doctrine: we will of course never store plain-text passwords:…
Pagerfanta Pagination
…
This is all we need to use Pagerfanta. In the controller, start with
$adapter = new DoctrineORMAdapter() - since we're using Doctrine - and pass it
the query builder. Next, create a $pagerfanta variable set to new Pagerfanta()
and pass it the adapter.
On the Pagerfanta…
Filtering / Searching
…things by returning $qb
at the bottom:
If you were using something like Elastic Search, then you wouldn't be making this
query through Doctrine: you'd be doing it through elastic search itself. But the
idea is the same: prepare some search for Elastic…
Adding Links via Annotations
…a few minutes!
To create this cool system, we need to understand a bit about annotations. Every
annotation - like Table or Entity from Doctrine - has a class behind it. That
means we need a Link class. Create a new directory called Annotation. Inside
add a…
Joins and addSelect Reduce Queries
…That's different from SQL, where selecting all
the fields from a joined table will give you more fields in your result.
Here, addSelect() just tells Doctrine to fetch the FortuneCookie data,
but store it internally. Later, when we access the FortuneCookies for a
Category…
Selecting Specific Fields
…s an awesome error:
This is what it looks like when you mess up your DQL. Doctrine does a really
good job of lexing and parsing the DQL you give it, so when you make a mistake,
it'll give you a pretty detailed error…
Making Fixtures Awesome with Alice
…files, and the same DoctrineFixturesBundle
that we were talking about before. This is a really nice combination because
it's going to mean that we can still run our normal php app/console doctrine:fixtures:load.
But after that, instead of writing raw PHP code…
Welcome to Symfony!
…requests, responses and
templating.
Get comfortable with a few extra tools, like Doctrine for dealing with
the database and code generation tools.
And the real reason you are here, to learn enough best practices and tips
to impress your friends at a party.
Ready? Let…
FOSUserBundle
…stored in the database. Let’s create
a new bundle called UserBundle to house the new entity. Instead of using
the doctrine:generate:bundle task, I’ll just create a UserBundle
and make sure there’s a properly-named bundle class inside. Don’t forget…
How to handle dynamic Subdomains in Symfony
…differences here are a bit subtle. For example, the baseHost is now
stored in a property and we can get Doctrine’s repository through the $em
property. We’ve also replaced the createNotFoundException call by instantiating
a new NotFoundHttpException instance. The createNotFoundException
method lives in…
Content Browser
…when we try the page, we're greeted with an error!
Netgen Content Browser backend for doctrine_recipe value type does not exist.
Yep! We need to implement a class that helps Layouts browse our recipes. That's
called a "content browser".
Adding a content…
Item View Template
…match one piece of config, like
this template, with some other piece of config, like the doctrine_recipe value
type. There are a finite number of these matchers, and we're going to see the most
important ones along the way. So don't worry…
Value Converter
…s an instanceof Recipe:
Second, for getValueType(), return the internal key of our value type:
doctrine_recipe:
Next is getId()... and we're literally going to return our ID with
$object->getId():
We don't have autocomplete on this, but we know this object will…
Adding Lists: Value Type
…The same is true if you're using Ibexa CMS.
So here's our next big goal: to add our Recipe Doctrine entity as a "value
type" in layouts so that we can create lists and grids containing recipes.
Step one to adding a value…
Enhanced Docker Integration & Testing Emails
…Finally, just like normal, thanks to our
config/packages/doctrine.yaml configuration, the DATABASE_URL environment variable
is used to talk to the database. So the Symfony binary plus Docker is a nice way
to quickly and easily boot up external services like a database…
Triaging a Bug Issue
…the user says that he got an error when trying to serialize a Doctrine
QueryBuilder with the web profiler: something about not being able to serialize
a PDO instance.
The web profiler works by collecting a bunch of information about the request
and serializing it…
x
1000+