1000 search results

PropertyFilter: Sparse Fieldsets

…From a high-level, a filter is basically a way for you to modify the Doctrine query that's made when fetching a collection. There's one more filter I want to talk about... and it's a bit special: instead of returning less results…

5:34
API Debugging with the Profiler

…the goodies that you expect - cache, performance, security, Doctrine, etc. In addition to the little web debug toolbar AJAX tracker we just saw, there are a few other ways to find the profiler for a specific API request. First, every response has an x-debug…

3:17
Our First ApiResource

…database exists: php bin/console doctrine:database:create And now run make:migration: Let's go check that out to make sure there aren't any surprises: CREATE TABLE cheese_listing... Yea! Looks good! Close that and run: php bin/console doctrine:migrations:migrate Brilliant…

5:37
App & Test Setup

…who can publish an item under different conditions. Then we'll do everything custom: add completely custom fields, completely custom API resources that aren't backed by Doctrine, custom filters and we'll even dive deep into API Platform's input and output DTO system…

7:44
Detecting the "Published" State Change

…Methods" and add the three method that we need: Before we fill in the code, let's immediately inject the doctrine data persister so that we can use it to do the actual saving. Add public function __construct() with DataPersisterInterface $decoratedDataPersister: I'll hit Alt…

9:08
Completely Custom Field via a Data Provider

…providers that load one object for the item operations. Normally, we don't need to think about this system because API Platform has a built-in Doctrine data provider that handles all of it for us. But if we want to load some extra data…

9:19
Custom Item Data Provider

…it extends a less strict ItemDataProviderInterface. I'm implementing that other crazy interface because that's what the core Doctrine item data provider uses... and I want to be able to pass it the same arguments. Ok: go to the "Code"->"Generate" menu - or…

6:57
Setting a Custom Field Via a Listener

…We just set the $isMe field on the authenticated User object. One cool thing about Doctrine is that if API platform later queries for that same user, Doctrine will return this exact object in memory, which means that the $isMe field will be set to…

5:32
Adding & Populating the Custom Field

…find the original tab and refresh. Oh! It's not an array of users! It's a Paginator object with a Doctrine Paginator inside! So... this obviously isn't an array, but the Paginator object is iterable: we can loop over it like an array…

5:10
Core Listeners & Accessing the "Resource" Objects

…fine... because nobody is the currently-authenticated user in a console command anyways. But if you did want a custom field to be populated everywhere - even in a console command - we have one more solution: a Doctrine postLoad listener. Let's check that out next…

4:37
Custom Resource Data Provider

…as the identifier? In Doctrine, it happens automatically thanks to the @ORM\Id annotation: When you're not in an entity - or if you want to use a field other than the database id in an entity - you can add @ApiProperty() with identifier=true: Cool! Let…

6:40
Collection "Types" and readableLink

…lot of metadata about each property, like its type and whether it's required. And it gets that from many different sources like Doctrine metadata and our own PHPDoc. And because collecting all of this can take time, it caches it. Now, API Platform is…

7:12
Custom Filter, getDescription() & properties

…implement an interface or extend some base class. In this case, we need to extend AbstractFilter. Make sure you get the one from Doctrine ORM... it's actually impossible to see which one we have here... so I'll randomly guess: Hey! I got it…

7:09
Output Properties & Metadata

…that's no surprise! When we serialize a CheeseListing entity, API Platform can use the Doctrine metadata above the title property to figure out that it's a string: But in this case, when it looks at title, it doesn't get any info about…

7:14
Custom Filter Logic for Entities

… Our filter is working! So this is what it looks like to make a custom filter when your resource is a Doctrine entity. But the process is different if you need to make a custom filter for an API resource that is not an entity…

8:25
Input Data Transformer

…object. Second, we transform that CheeseListingInput into a CheeseListing in the data transformer. And third, the normal Doctrine data persister saves things. That's a really clean process! Go back to the docs and look at the put operation that updates cheeses. Will this work…

4:24
Type Validation

…its work, it first tries to figure out what type the field should be, which we know it does in a number of different ways, like reading Doctrine metadata, setter argument type-hints and even PHPDoc. Then, for scalar types like the int price, if…

7:29
UUID's

…how do we generate these UUID strings? Symfony 5.2 will come with a new UUID component, which should allow us to easily generate UUID's and store them in Doctrine. But since that hasn't been released yet, we can use ramsey/uuid, which…

7:29
UUID as a API Identifier

…talked about it before. Go to the top of User. Every API Resource needs an identifier. And when you use Doctrine, API Platform assumes that you want the database id as the identifier. To tell it to use something different, add @ApiProperty() with identifier=false: That…

5:16
Using a Base Email Template

…data is fresh... with recent article created dates. Run: php bin/console doctrine:fixtures:load This should add enough users and articles that about 1-2 authors will be subscribed to the newsletter and have recent articles. Try that command: Ha! It didn't explode…

8:54