Chapters
20 Chapters
|
1:18:30
|
Login to bookmark this video
-
Course Code
Subscribe to download the code!Compatible PHP versions: >=5.5.9
Subscribe to download the code!Compatible PHP versions: >=5.5.9
-
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!
03.
Saving Related Resources in a Form
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!
This tutorial uses an older version of Symfony. The concepts of Hypermedia & HATEOAS are still valid. But I recommend using API Platform in modern Symfony apps.
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": ">=5.5.9",
"symfony/symfony": "3.0.*", // v3.0.3
"doctrine/orm": "^2.5", // v2.5.4
"doctrine/doctrine-bundle": "^1.6", // 1.6.2
"doctrine/doctrine-cache-bundle": "^1.2", // 1.3.0
"symfony/swiftmailer-bundle": "^2.3", // v2.3.11
"symfony/monolog-bundle": "^2.8", // v2.10.0
"sensio/distribution-bundle": "^5.0", // v5.0.4
"sensio/framework-extra-bundle": "^3.0.2", // v3.0.14
"incenteev/composer-parameter-handler": "~2.0", // v2.1.2
"jms/serializer-bundle": "^1.1.0", // 1.1.0
"white-october/pagerfanta-bundle": "^1.0", // v1.0.5
"lexik/jwt-authentication-bundle": "^1.4", // v1.4.3
"willdurand/hateoas-bundle": "^1.1" // 1.1.1
},
"require-dev": {
"sensio/generator-bundle": "^3.0", // v3.0.6
"symfony/phpunit-bridge": "^3.0", // v3.0.3
"behat/behat": "~3.1@dev", // dev-master
"behat/mink-extension": "~2.2.0", // v2.2
"behat/mink-goutte-driver": "~1.2.0", // v1.2.1
"behat/mink-selenium2-driver": "~1.3.0", // v1.3.1
"phpunit/phpunit": "~4.6.0", // 4.6.10
"doctrine/doctrine-fixtures-bundle": "^2.3" // 2.3.0
}
}
6 Comments
Hello,
Why EntityType in web forms render a list of projects , and in Api world it renders just a project ?
Hey mehdi
Sorry for the confusion but Ryan meant that it would return an array of Project objects
Cheers!
Hello,
I read that we should avoid in 90% caces Entity Form type because we will have usually hundreds of entities and app will work slowly (Iin this case api). What we can do in API if we have 500 Programmers and 200 Projects. How to optimize app (api)?
Hey again!
Hmm, I would wait for it to be a problem, if you start seeing that your API response slowly, then you can hunt down which part is the bottle neck and look for an optimization (a query, a process, etc)
Cheers!
One question about flush().
For example:
If we have controller which calls 3 services (every create new collection of objects), so we will need to call ->persist($entity) method inside foreach() in every service. But where to call flush()? Only once in controller before return Response() or in every servise - so this is 3 times.
I am not sure whether is good idea that service only persist objects and controllers call flush()?
Hey axa!
It depends, as always, you can call flush more than once in a request, is not a big deal, but if you are going to do it, is better if you have a reason. In your case, I would consider making every service to call flush so you can save your work in case that another service fails, or maybe you want all the opposite and only flush if everything worked as spected
Cheers!
"Houston: no signs of life"
Start the conversation!