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
}
}
12 Comments
Hello,
I'm using Api pltform distribution to develop my newest app and it is a great experience!
However, I noticed a memory issue whlie using Foundry factories and
doctrine:fixtures:load.I'm trying to use these to setup testing data for my application. While preparing basic config like some users, organization and permissions everything was okay, but when I wanted to seed some Issues in greater number (but not some enormous amounts, it was like 300) I encountered "Allowed memory size of X bytes exhausted" error.
When I printend used memory inside
createManycallback function usingmemory_get_usageI noticed it increases with each iteration ultimately causing the memory error.I though this could be due to SQL logging as decribed in many places, so I tried to disable it using
doctrine:fixtures:load --no-debugor$manager->getConnection()->getConfiguration()->setSQLLogger(null);in myAppFixtures::loadmethod, but it didn;t help :/.I know that when inserting big amounts of data with entity manager one should call
flushmethod in certain intervals, to keep the memory usage at bay, but I assume this should be solved when using factory'screateManymethod, which indeed is meant to insert lots of fake data into database.I use doctrine-bundle 2.12, with doctrine/data-fixtures 1.7, doctrine/doctrine-fixtures-bundle 3.6.1 and zenstruck/foundry 2.1
Is there anything obvious I'm missing here?
I can't play the video (lesson 12), this is the error : The media could not be loaded, either because the server or network failed or because the format is not supported.
Hey Mickael,
We're sorry to hear you're experiencing trouble accessing this video. This happens sometimes when the video was on pause for a long time. The full page refresh should help. If not - try to download the video and watch it locally. I just double-checked the video - it works great for me, so it might be a temporary outage of Vimeo - the hosting provider behind our videos - or something related to your local network. Anyway, downloading the video and watching it locally should help. Let us know if you still have problems with it!
Cheers!
I cleared cache and now it works :)
Beautiful - sorry again about that!
What do I need to do to have a custom paginator (or DataProvider??) so that I can pass an offset and limit instead of items_per_page and a page_number?
Javascript code that I have no control over expects a slice of the data, not a page.
As a hack, I passed a "start" parameter (which will of course be seen as a filter), and replaced the offset (leaving items_per_page along, as that functions as the limit too). This is exactly what I want -- to control the starting offset, not the page.
Doctrine\Orm\Extension\PaginationExtension,php
More details at https://github.com/api-platform/core/issues/4672 -- I'd LOVE to be able to solve this problem, as I have a hack that does two larger-than-necessary API calls and then slices the result as needed. Ugh.
Hey @Tac-Tacelosky
Perhaps you need a cursor or partial pagination, you can learn more about them in the docs https://api-platform.com/docs/core/pagination/#cursor-based-pagination
Also, remember that you can "decorate" APIPlatform services to extend/modify their behavior
Cheers!
Hi!
I am working on an API Platform 3 (Symfony 6) app.
In my JSON response, I have the following :
{ ... "totalItems": 7065, "itemsPerPage": 10, ... }
Is it possible to change the config (or do something else) so that I get :
{ ... "total_items": 7065, "page_size": 10, ... }
So basically I want to rename these fields, in the JSON response. Is it possible ?
I emphasize that I want to override the default fields (totalItems and itemsPerPage) in the JSON response.
Thanks!
Hey Marko,
I couldn't find any config to change those field names in the documentation. So, what I think you could do is create an event listener and override those fields directly on the response data. https://api-platform.com/docs/core/events/
Cheers!
Hello! Thanks a lot for your answer. Actually, according to this link, GraphQL is not supported by the event system. Given that we may actually migrate from REST to GraphQL in the future, do you think there is another way to override these field names ? Because, with GraphQL, what we implemented with events will not work anymore. Maybe we can use some normalizer or anything else, compatible with GraphQL, to achieve the same goal ?..
It actually worked with a custom normalizer. According to API Platform doc, unlike event system, normalizers & denormalizers are GraphQL friendly
Hey Marko,
Oh, I didn't know that about GraphQL. Anyways, I'm glad to know you could solve your problem.
By the way, remember that you can "decorate" any services to add extra behavior to them https://api-platform.com/docs/core/extending/#leveraging-the-built-in-infrastructure-using-composition
Cheers!
"Houston: no signs of life"
Start the conversation!