Value Loader + Preview Template
…it chose to do an odd thing: explode! The Ajax call that failed says:
Value loader for doctrine_recipe value type does not exist.
To review: we have a custom value type called doctrine_recipe, which we created
so that we could add grids and…
Adding a Comment Entity
Hey friends! I mean, hello fellow space-traveling developer... friends. Welcome,
to part two of our Doctrine tutorial where we talk all about... relationships.
Oh, I love relationships, and there are so many beautiful types in the universe!
Like, the relationship between two old friends…
Adding the ManyToOne Relation
…to have many Comments... and we want each Comment to
belong to one Article. Forget about Doctrine for a minute: let's think about how
this should look in the database. Because each Comment should belong to one
article, this means that the comment table…
Owning Vs Inverse Relations
We need to talk about a very, very important and, honestly, super-confusing part
of Doctrine relations! Listen closely: this is the ugliest thing we need to talk
about. So, let's get through it, put a big beautiful check mark next to it, then…
Dynamic Roles and Canonical Fields
Let's see what this all looks like in the database! To query the user table,
we can actually use the console:
php bin/console doctrine:query:sql 'SELECT * FROM user'
Nice! We inherited a bunch of columns from the base User class, like username…
Criteria System: Champion Collection Filtering
…But if - in our template, for example - we wanted to loop over the experts,
maybe to print their names, Doctrine would be smart enough to make a SELECT statement
for that data, instead of a COUNT. But that SELECT would still have the WHERE clause…
Create Genus Note
…again! Welcome back friend! In this tutorial, we're diving back into
Doctrine: this time to master database relations. And to have fun of course - databases
are super fun.
Like usual, you should code along with me or risk 7 years of bad luck. Sorry…
Keep Going!
…was probably the most important episode yet,
and you made it. Congrats!
The first big piece included the two main Doctrine associations: ManyToOne
and ManyToMany. We saw how each can have an optional inverse side, like
the OneToMany side of ManyToOne.
The second huge piece…
An Aside: Dependency Injection Parameters
…forms stuff and open config.yml. Under
the doctrine key, we see a bunch of percent sign values:
# app/config/config.yml
# ...
doctrine:
Whenever you see something surrounded by two percent signs in a config file,
it’s a parameter. Parameters are like variables: you…
OneToMany: The Inverse Side of a Relationship
…we gave every Event an owner. This was our first Doctrine relationship:
a ManyToOne from Event to User.
This lets us do things like call $event->getOwner(). Let’s use this to
print the owner of an Event:
{# src/Yoda/EventBundle/Resources/views/Event/show…
Fixtures: For some dumb data
…it
there:
To see if it's working, try getting help information on a new doctrine:fixtures:load
console task that comes from the bundle:
php app/console doctrine:fixtures:load --help
We see the help information, so we're ready to write some fixtures…
Starting in Symfony2: Course 2 (2.4+)
…we're going to take you through some of the most difficult areas of Symfony learning all about security, forms, and parts of Doctrine. We'll also see testing and learn more about how Symfony's service container works. When you get to the end…
Migrations
…it's a PHP class where the up() method holds the SQL to create our table.
What's neat is how this was created: Doctrine compared the current state of our
entities to the database and generated the SQL needed to make them match.
Wow…
Inserting Data via Fixtures
…paste some code from the tutorial/ directory.
We now have three ship objects, but nothing has been saved - or persisted to the
database yet. But interesting, Doctrine passes us an ObjectManager.
This is the heart of Doctrine. We'll use it to save, fetch, update…
Fetching with DQL, the QueryBuilder & find()
…query, in this case,
our homepage() method.
One bummer is that DQL isn't that pretty!
Luckily, Doctrine has a "query builder". This thing is awesome: instead of writing
the DQL string manually, we build it with an object.
Back in our homepage() method, replace…
Cosmic Queries: the Repository Class
…Cool! We have an App\Repository\StarshipRepository
object. Go check out this class: src/Repository/StarshipRepository.php.
First, if you're curious how Doctrine knows this class is the repository for the
Starship entity, jump into src/Entity/Starship.php. Ah, the #[ORM\Entity]
attribute…
Pagination
…s a generic pagination library
but has great Doctrine integration! Add the two required packages:
composer require babdev/pagerfanta-bundle pagerfanta/doctrine-orm-adapter
Scroll up to see what this installed. pagerfanta/doctrine-orm-adapter is the glue between
Pagerfanta and Doctrine.
On our homepage…
Symfony Forms: The Basics
…this course, you’ll learn how to:
Install and configure the Symfony Form component
Build form types with Maker and map them to Doctrine entities
Understand the difference between Form and FormView
Render forms and fields using Twig’s helper functions
Use form_start(), form…
x
1000+