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…
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…
Making Questions owned by Users
Our site has users and these questions are created by those users. So in the
database, each Question needs to be related to the User that created it
via a Doctrine relationship. Right now, if you open src/Entity/Question.php,
that is not the…
Timestampable & Failed Migrations
…Yup! It looks
good: it adds the two columns.
Back at the terminal, run it with:
symfony console doctrine:migrations:migrate
And... yikes!
Invalid datetime format 0000 for column created_at at row one.
The problem is that our database already has rows in the…
DQL & The Query Builder
…back is a custom class. Well, technically you don't have to have a custom
repository class - and if you don't, Doctrine will just give you an instance of
EntityRepository. But in practice, I always have custom repository classes.
Anyways, when we ask for…
Persisting to the Database
…How can I insert a new row in the question table?
We need to think:
Let's create a Question object, populate it with data and then ask Doctrine
to save it.
To play with all of this, let's add a new, sort of…
Migrations
…the database. But... that table does not exist yet.
How can we create it?
Well, because Doctrine has all of this configuration about the entity, like
the fields and field types, it should - in theory - be able to create the table
for us. And... it…
Fixing our Deprecations: Form, Controller & Mailer
…the current list for the homepage.
There are technically 12 deprecations. But remember, we can ignore all the
ones from doctrine/persistence because they're not related to Symfony.
With that in mind... if you look closely, there are really only two real
deprecations left..…
Upgrading to Symfony 5.0
We've done it! We fixed all the deprecations in our app... except for the
doctrine/persistence stuff, which we don't need to worry about because we're
not upgrading that library. That means... we are ready for Symfony5!
How... do we actually upgrade…
File Uploads & Data Fixtures
Open up src/DataFixtures/ArticleFixtures.php. Here's how this works: this function
creates 10 articles whenever we run bin/console doctrine:fixtures:load. It's a cool
helper we created in our Symfony series. But, the setImageFilename() stuff
is now a problem. We know…
The Server & New IsGranted
… First, in .env, change the database name to symfony3_tutorial,
or whatever the database name was called when you first setup the project. Now
when we run doctrine:migrations:status... yes! We have a full database!
Let's start the built-in web server:
./bin…
Aliases & When Autowiring Fails
…wrong. Right now, the
MarkdownTransformer class has two arguments, type-hinted with MarkdownParserInterface
and Cache from Doctrine:
But, these are not being autowired: we're explicitly specifying each argument:
If I were creating this service today, I actually wouldn't specify any configuration
at first…
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…
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…
Creating the User Class
…If we had said no to the password question earlier, this interface wouldn't be implemented.
Back in User, we see the standard Doctrine entity class attribute: ORM\Entity. We also have this
ORM\UniqueConstraint attribute. This creates a unique index on the email column…
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…
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…
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…
x
1000+