Chapters
48 Chapters
|
5:13:28
|
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!
27.
Custom Filter for Custom Resources
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.
This tutorial also works great with API Platform 2.6.
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": ">=8.2",
"ext-ctype": "*",
"ext-iconv": "*",
"api-platform/core": "^2.1", // v2.5.10
"composer/package-versions-deprecated": "^1.11", // 1.11.99
"doctrine/annotations": "^1.0", // 1.12.1
"doctrine/doctrine-bundle": "^2.0", // 2.1.2
"doctrine/doctrine-migrations-bundle": "^3.0", // 3.0.2
"doctrine/orm": "^2.4.5", // 2.8.2
"nelmio/cors-bundle": "^2.1", // 2.1.0
"nesbot/carbon": "^2.17", // 2.39.1
"phpdocumentor/reflection-docblock": "^3.0 || ^4.0 || ^5.0", // 5.2.2
"ramsey/uuid-doctrine": "^1.6", // 1.6.0
"symfony/asset": "5.1.*", // v5.1.5
"symfony/console": "5.1.*", // v5.1.5
"symfony/debug-bundle": "5.1.*", // v5.1.5
"symfony/dotenv": "5.1.*", // v5.1.5
"symfony/expression-language": "5.1.*", // v5.1.5
"symfony/flex": "^1.1", // v1.21.6
"symfony/framework-bundle": "5.1.*", // v5.1.5
"symfony/http-client": "5.1.*", // v5.1.5
"symfony/monolog-bundle": "^3.4", // v3.5.0
"symfony/security-bundle": "5.1.*", // v5.1.5
"symfony/twig-bundle": "5.1.*", // v5.1.5
"symfony/validator": "5.1.*", // v5.1.5
"symfony/webpack-encore-bundle": "^1.6", // v1.8.0
"symfony/yaml": "5.1.*" // v5.1.5
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.3", // 3.3.2
"symfony/browser-kit": "5.1.*", // v5.1.5
"symfony/css-selector": "5.1.*", // v5.1.5
"symfony/maker-bundle": "^1.11", // v1.23.0
"symfony/phpunit-bridge": "5.1.*", // v5.1.5
"symfony/stopwatch": "5.1.*", // v5.1.5
"symfony/twig-bundle": "5.1.*", // v5.1.5
"symfony/web-profiler-bundle": "5.1.*", // v5.1.5
"zenstruck/foundry": "^1.1" // v1.8.0
}
}
7 Comments
This is just FYI as I am using API Platform 2.6.8.
The desciption for the filter in the documentation was not working for me.
Instead of:
It looks like it is now is now:
I figured it out by looking in
vendor/api-platform/core/src/OpenApi/Factory/OpenApiFactory.phparound line 415.The same is true for the <b>CheeseSearchFilter</b>.
becomes
Thanks for the Tutorials!
Hey Scott,
Thank you for sharing this workaround! We will investigate things further and most probably add a note. It sounds like new version of ApiPlatform changes some things.
Cheers!
Hi,
if someone would like to check the solution for "hydra:totalItems:" proper value, here is mine.
First, wipe out statsHelper in DailyStatsPaginator getTotalItems() method so this method will call self count() method.
Second, in count() method we need to count items a nested array and I did it like that:
I don't know if this solution is efficient but in this case it works. Maybe more experienced programmers might say something about this.
I hope my comment proves helpful for someone.
Jakub
But there is a little problem with my solution. I didn't realise at first moment that after doing this I lost whole 'hydra:view' section in response body. For this moment I don't know why this happened. Maybe someone would like to help me with this.
Hey Jakub!
Yea.. this is probably going to cause 1 of 2 different problems. First, I think this might only "loop" over the items on the page? So if there are 30 total items, but only 5 are showing on the page, then this would incorrectly show 5.
If it DID loop over all 30, then that is, indeed, a performance issue as you would be loading all 30 just to get the count. Of course, if you don't have a huge data set, it's not actually a problem ;).
The "correct" solution would depend on what your data source is. For example, if your items are stored in a database, you would take the query that you use to get the results and execute it a second time, but without the LIMIT & OFFSET - a this time just do do a quick COUNT. If your dataset is JSON... you could update my
count()method JUST to count the number of "items" in the JSON and skip actually creating theDailyStatsobject.I'm not sure about this... I wouldn't think that this would be related to how you changed the "count" part. But let me know if I'm wrong.
Cheers!
So what you
Ok. Now I know what's going on with this 'hydra:view' section. Whether it appears depends on the number stored in "hydra:totalItems". If this number is greater than stored in annotation "paginationItemsPerPage", then the 'hydra:view' section will appear.
Anyway, thank you for anser.
"Houston: no signs of life"
Start the conversation!