1000 search results

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
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
Publish State Change Validator Logic

… Or true to false? Or maybe it's not changing at all because the PUT request is only updating other fields. And hey! We already know how to get the original data from Doctrine! We did it in CheeseListingDataPersister: Oh, and by the way: if…

8:26
Decorating Data Persisters vs Context Builders

…called just DataPersister. Back in PhpStorm, hit Shift+Shift, search for DataPersister and make sure to include "non-project items". Select the one from ApiPlatform's Doctrine Bridge. And... cool! This looks pretty much exactly like we expected: it persists and flushes. This is what…

8:54
Data Persister Decoration

…object and validates it, it tries to save or persist that object. Usually, this means that we're saving an entity object to the database via Doctrine. But we could "save" an object anywhere, like by sending the data to another API, or putting it…

6:48
Attachments with Async Messenger Emails

…are a bunch of deprecation notices, but the tests do pass. However, run that Doctrine query again to see the queue: Uh oh... the email - the one from our functional test to the registration page - was added to the queue! Why is that a problem…

3:57
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
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
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
Pagination

…way long. Not only will this page become hard to use, it will quickly slow down until it stops working. If you ever need to query and render more than 100 Doctrine entities, you're going to have slow loading times. If you try to…

9:19
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
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
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
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
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
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
Integration Tests

…if you mock everything... there's nothing really left to test For example, how would you test that a complex query in a Doctrine repository works? If you mock the database connection then... I guess you could test that the query string you wrote looks…

9:18
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
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
parameters.yml & %kernel.root_dir%

…the path from it. Earlier, just to show off, we configured the DoctrineCacheBundle to store the markdown cache in /tmp/doctrine_cache: Referencing absolute paths is a little weird: why not just store this stuff in Symfony's cache dir? Ok, ok, the bundle actually…

4:48