Chapters
26 Chapters
|
2:18:26
|
This course is archived!
This tutorial uses a deprecated micro-framework called Silex. The fundamentals of REST are still ?valid, but the code we use can't be used in a real application.
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!
-
Course Script
Subscribe to download the script!
Subscribe to download the script!
20.
We can Embed Resources Too
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 uses a deprecated micro-framework called Silex. The fundamentals of REST are still ?valid, but the code we use can't be used in a real application.
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"silex/silex": "~1.0", // v1.3.2
"symfony/twig-bridge": "~2.1", // v2.7.3
"symfony/security": "~2.4", // v2.7.3
"doctrine/dbal": "^2.5.4", // v2.5.4
"monolog/monolog": "~1.7.0", // 1.7.0
"symfony/validator": "~2.4", // v2.7.3
"symfony/expression-language": "~2.4", // v2.7.3
"jms/serializer": "~0.16", // 0.16.0
"willdurand/hateoas": "~2.3" // v2.3.0
},
"require-dev": {
"behat/mink": "~1.5", // v1.5.0
"behat/mink-goutte-driver": "~1.0.9", // v1.0.9
"behat/mink-selenium2-driver": "~1.1.1", // v1.1.1
"behat/behat": "~2.5", // v2.5.5
"behat/mink-extension": "~1.2.0", // v1.2.0
"phpunit/phpunit": "~5.7.0", // 5.7.27
"guzzle/guzzle": "~3.7" // v3.9.3
}
}
2 Comments
Hi Ryan,
I have a question about the number of queries to the database when using JMSSerializer and HateoasBundle.
Example:
An entity A is associated with OneToOne to entity B through property $b.
class A
{
...
/**
@ORM\OneToOne(targetEntity="B")
# If I put @Serializer\Expose() Internally it generates a query extra to get the data of the table B. It also happens if I use the embedded annotation.
*/
private $b
}
This would be the right thing, but in my controller I have a query with join that pulls me all the data from both tables.
How do I do this with a single query? It's possible?
I have also tried to use fetch EAGER of doctrine, but still performing 2 query..
Any ideas?
Thank you very much
Hi Juan!
Hmm, it sounds like you correctly understand that if you query with a join, then the serializer should *not* be making these queries. So, this *is* weird! 2 things to check for:
1) If you Simply say $a->getB() in your controller (don't use the serializer temporarily), can you verify that the extra query is NOT made?
2) On your join, do you have an addSelect like described here? http://knpuniversity.com/sc...
In short, the serializer is kind of "stupid" - it simply knows that it should access the "b" property on A and use it to serialize into JSON. It doesn't know that Doctrine exists, and so shouldn't be interfering with how the queries are made for stuff. Well, that's how it *should* be working at least :).
Cheers!
"Houston: no signs of life"
Start the conversation!