Chapters
28 Chapters
|
2:51:42
|
Login to bookmark this video
-
Course Code
Subscribe to download the code!
Subscribe to download the code!
-
This Video
Subscribe to download the video!
Subscribe to download the video!
-
Subtitles
Subscribe to download the subtitles!
Subscribe to download the subtitles!
-
Course Script
Subscribe to download the script!
Subscribe to download the script!
Scroll down to the script below, click on any sentence (including terminal blocks) to jump to that spot in the video!
Subscribe to jump to this part in the video!
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": ">=8.2",
"ext-ctype": "*",
"ext-iconv": "*",
"api-platform/core": "^3.0", // v3.0.8
"doctrine/annotations": "^1.0", // 1.14.2
"doctrine/doctrine-bundle": "^2.8", // 2.8.0
"doctrine/doctrine-migrations-bundle": "^3.2", // 3.2.2
"doctrine/orm": "^2.14", // 2.14.0
"nelmio/cors-bundle": "^2.2", // 2.2.0
"nesbot/carbon": "^2.64", // 2.64.1
"phpdocumentor/reflection-docblock": "^5.3", // 5.3.0
"phpstan/phpdoc-parser": "^1.15", // 1.15.3
"symfony/asset": "6.2.*", // v6.2.0
"symfony/console": "6.2.*", // v6.2.3
"symfony/dotenv": "6.2.*", // v6.2.0
"symfony/expression-language": "6.2.*", // v6.2.2
"symfony/flex": "^2", // v2.2.4
"symfony/framework-bundle": "6.2.*", // v6.2.3
"symfony/property-access": "6.2.*", // v6.2.3
"symfony/property-info": "6.2.*", // v6.2.3
"symfony/runtime": "6.2.*", // v6.2.0
"symfony/security-bundle": "6.2.*", // v6.2.3
"symfony/serializer": "6.2.*", // v6.2.3
"symfony/twig-bundle": "6.2.*", // v6.2.3
"symfony/ux-react": "^2.6", // v2.6.1
"symfony/validator": "6.2.*", // v6.2.3
"symfony/webpack-encore-bundle": "^1.16", // v1.16.0
"symfony/yaml": "6.2.*" // v6.2.2
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.4", // 3.4.2
"symfony/debug-bundle": "6.2.*", // v6.2.1
"symfony/maker-bundle": "^1.48", // v1.48.0
"symfony/monolog-bundle": "^3.0", // v3.8.0
"symfony/stopwatch": "6.2.*", // v6.2.0
"symfony/web-profiler-bundle": "6.2.*", // v6.2.4
"zenstruck/foundry": "^1.26" // v1.26.0
}
}
23 Comments
If you have problem with /api Entrypoint:
use this:
not this
Hey Domin,
Thank you for this tip! Yeah, we definitely want the filter for ORM not ODM as we use Doctrine ORM in this project :) But yeah, easy to miss this tiny difference in the long namespace, so it might be helpful for others.
Cheers!
In the "Script" version of this tutorial, you forgot the call to ApiFilter class here:
Hi,
when you want to activate filters for all booleans by default in your resource you need to only put:
#[ApiFilter(BooleanFiler::class)]above class and of course, remember about proper 'use' statements.
Jakub
Ha! I didn't know that - very cool!
Filters are so easy to use!
But from what I get they always work by generating some query parameter.
How can I set headers in swaggerUI similar to query parameters so that the user can set those headers in the UI?
I'd like to have some filters as headers instead of query parameters.
Hey @Fireball
I'm not sure if ApiPlatform gives you that functionality out of the box, it sounds to me like you'll need to create a custom filter
Cheers!
It might be a litte late for the topic starter, but for everybody else trying to do the same – you might want to look into declaring parameters on resources: https://api-platform.com/docs/core/filters/#declaring-parameters
Cool, thank you for sharing it!
Hello @weaverryan
The problem with the ARRAY error is still here "Undefined constant Doctrine\DBAL\Types\Types::ARRAY" despite this https://github.com/symfony/maker-bundle/issues/1437
I didn't want to downgrade to dbal 3.8 has advise by others.
To make it works, i've just add "public const ARRAY = 'array';" in vendor/doctrine/dbal/src/Types/Types.php
So far so good
Hey @weaverryan
I'm updating from version 2.7 to 3.0.
The filters are completely ignored, nothing absolutely changes at all.
I tried even with a vanilla project without success.
I know it is a long shot, but where should I start to look ?
Hey @Thomas-K!
Ah! Hmm. So, just "normal" built-in (not custom) filters don't work? You don't see them in the documentation and trying to manually add the query parameters doesn't work? That's very bizarre, especially in a fresh project. It makes me think (?) that maybe you're doing some subtle formatting wrong (e.g. on the attributes) and API Platform isn't seeing them? It's definitely a very odd thing, which often means it's something really subtle that's causing the issues. Do you have any special config setup - or are you using PHP attributes for the
#[ApiResource]like normal?Cheers!
Across the SearchFilter: Filter by Text section, you mention multiple times the
titleproperty, that should be thenameproperty.Hey @Alex-K
You're right! Ryan got confused. However, there's not a
titleproperty on the entity, so we could say thenameproperty is actually the title :DCheers!
Hi,
I have the following filter
but it returns an array of elements.
Is it possible to make it return a single element like findOneBy method inside Entity Repository?
Hey @Dmitriy!
Hmm, probably not. The problem is that the filters are only used on your "collection" endpoint - e.g.
/api/treasures, and these always return an array of items, even if it's an array of 1 thing. And that's by design: no matter what, when you use the "collection" endpoint, you get a collection back - and you can predict it's structure. It might actually be possible to return a single item (by creating a custom state provider, calling the core provider, then changing the array of 1 item to just an object and returning it from your state provider), but that's a lot of extra work to make your endpoint operate in a non-standard way. So my advice is: keep it as an array and keep it simple :).Cheers!
Thank you. It's a pity that everything is so complicated. I'll keep it simple)
Good morning.
I am very interested in the integration of the Api platform with Elastic Search to implement it.
Would you have a link, manual or video that explains it.
Or are you going to take a course on that?
Thank you.
Hey @Patricio-RM!
We don't have any plans to cover that right now. But API Platform does have docs and official support for Elastic Search - https://api-platform.com/docs/core/elasticsearch/ - and especially in episode 3 - https://symfonycasts.com/screencast/api-platform-extending - we go deeper into understanding how state providers work, which would at least clarify how that is working. I've never used the Elastic Search integration myself, but it looks a lot like the Doctrine support: there is a built-in
CollectionProviderthat knows how to pull data from ElasticSearch and populate your custom class.I hope this short answer at least helps a little bit :).
Cheers!
I see that there are 2 classes BooleanFilter, one for mangoDB(ODM) and one for MySQL5(ORM), how would i make my application support both of them?
Hey @Wael-G
I'm not sure about the answer but your application will run on two different databases?
I am just assuming that I have 2 clients with different Database preferences.
In that case, I think you would have to implement some sort of a "select database" system and remember that option somehow (perhaps in cache). Then, any service communicating to the DB will have to check that config and use the corresponding DB. I'm not sure if there are bundles that can help you with it
Oh, also, you'll have to set up Doctrine to work with multiple databases https://symfony.com/doc/current/doctrine/multiple_entity_managers.html
I hope it helps. Cheers!
"Houston: no signs of life"
Start the conversation!