1000 search results

Completely Custom Resource

…directory, create a new class called DailyStats: And yes, I'm putting this in the Entity/ directory even though this isn't going to be a Doctrine entity. That's totally allowed and it's up to you if you like this or not. If…

5:25
Custom Filter apply()

…an admin. Why are we talking about these extension classes? Because one of the core Doctrine extensions is called FilterExtension. Let's open it up: Shirt+Shift and look for FilterExtension.php making sure to include all non-project items. Get the one from Orm\…

8:15
The N+1 Problem & EXTRA_LAZY

…familiar! We have the same number 1 exclusive-time function as before: UnitOfWork::createEntity(). In that situation, it meant that we were querying for too many items and so Doctrine was hydrating too many objects. Is it the same problem now? And if so, why…

5:59
Field Types & Options

…we now know that, because we've bound our form to our entity, the form type "guessing" system is able to read the Doctrine metadata, notice that content looks like a big field, and "guess" that it should be a textarea. Field type guessing is…

4:45
Collection Magic with Criteria

… But... there's a problem. If we did this, Doctrine would query for all of the comments, even though we don't need all of the comments. If your collection is pretty small, no big deal: querying for a few extra comments is probably fine…

7:45
Custom User Method

…the new file: And... yep! It looks perfect. Move back to your terminal one more time and run: php bin/console doctrine:migrations:migrate Excellent! Now that we have the new field, let's set it on our dummy users in the database. Open UserFixture…

6:18
Article Admin & Low-Level Access Controls

…you see this "Proxies" thing, ignore it. This is an internal object that Doctrine sometimes wraps around your entity in order to enable some of its lazy-loading relation awesomeness. The object looks and works exactly like User. Second, the error itself basically means that…

7:14
Saving Entities

… And, good news! This is probably one of the easiest things to do in Doctrine. Let's create a new controller called ArticleAdminController. We'll use this as a place to add new articles. Make it extend the normal AbstractController: And create a public function…

7:40
Query Logic Re-use & Shortcuts

…is to isolate the query logic that we need to share into its own private method. At the bottom, create a private function addIsPublishedQueryBuilder() with a QueryBuilder type-hint - the one from Doctrine\ORM - and $qb: Next, go up, copy that part of the query…

6:40
Activating Timestampable

… First, we need to activate it, which again, is described way down on the bundle's docs. Open config/packages/stof_doctrine_extensions.yaml, and add timestampable: true: Second, your entity needs some annotations. For this, go back to the library's docs. Easy enough…

4:03
Saving Relations

…to Doctrine. At the top, use the $manager variable: Then, $manager->persist($comment1): If we stop here, this is a valid Comment... but it is NOT related to any article. In fact, go to your terminal, and try the fixtures: php bin/console doctrine:fixtures…

4:35
Autowiring & Service Deprecations

…In Symfony 3, when Symfony saw a type-hint - like EntityManager - it would first look to see if there was a service or alias in the container with that exact id: so Doctrine\ORM\EntityManager. If there was not, it would then scan every service…

9:17
Clearing the Database

…end of kernel.project_dir! Now, find your terminal and create the var/data directory: Next, create the schema php bin/console doctrine:schema:create --env=test And, congrats! You are the owner of a fancy new var/data/test.sqlite file! Take good care of…

6:19
Optimizing with Cache

…do we need to clear this cache on each deploy? Nope! Internally, Symfony uses a cache namespace for Doctrine that includes the directory of our project. Since Ansistrano always deploys into a new releases/ directory, each deploy has its own, unique namespace. When provisioning finishes…

3:14
Handling Object Dependencies

…$this->assertCount(0) matches $enclosure->getDinosaurs(). Ok, good start! Next, inside Entity, create Enclosure. This will eventually be a Doctrine entity, but don't worry about the annotations yet. Add a private $dinosaurs property. And, like normal, add public function __construct() so that we can…

6:46
Configuring Specific (Named) Arguments

…clear out the arguments, and add $cache: '@doctrine_cache.providers.my_markdown_cache': The dollar sign is the important part: it tells Symfony that we're actually configuring an argument by its name. $cache here must match $cache here. And it works beautifully - refresh now…

3:10
Override Controllers

…and I want you to know both. Open the User entity. It has an updatedAt field: To set this, we could use Doctrine lifecycle callbacks or a Doctrine event subscriber. But, I want to see if we can set this instead, by hooking into EasyAdminBundle…

7:11
More about List Field Types

…which controls that dataType config. There are a bunch of built-in types, including all of the Doctrine field types and a few special fancy ones from EasyAdminBundle, like toggle. The "toggle" type is actually super cool: it renders the field as a little switch…

6:06
Deleting an Item from a Collection: orphanRemoval

…relationship: In other words, if we remove or add a GenusScientist from this array, it doesn't make any difference! Doctrine ignores changes to the inverse side. How to fix it? We already know how! We did it back with our ManyToMany relationship! It's…

5:14
Give me Clean URL Strings (slugs!)

…But! But, but but! I have good news: if we can understand just a few important concepts, Doctrine collections are going to fall into place beautifully. So let's take this collection of chaos and turn it into a collection of.. um... something awesome... like…

5:39