// composer.json
{
"require": {
"php": "^7.1.3",
"ext-iconv": "*",
"composer/package-versions-deprecated": "^1.11", // 1.11.99
"doctrine/doctrine-bundle": "^1.6.10", // 1.10.2
"doctrine/doctrine-migrations-bundle": "^1.3|^2.0", // v2.0.0
"doctrine/orm": "^2.5.11", // v2.7.2
"knplabs/knp-markdown-bundle": "^1.7", // 1.7.0
"knplabs/knp-time-bundle": "^1.8", // 1.8.0
"nexylan/slack-bundle": "^2.0,<2.2.0", // v2.0.0
"php-http/guzzle6-adapter": "^1.1", // v1.1.1
"sensio/framework-extra-bundle": "^5.1", // v5.1.4
"stof/doctrine-extensions-bundle": "^1.3", // v1.3.0
"symfony/asset": "^4.0", // v4.0.4
"symfony/console": "^4.0", // v4.0.14
"symfony/flex": "^1.0", // v1.21.6
"symfony/framework-bundle": "^4.0", // v4.0.14
"symfony/lts": "^4@dev", // dev-master
"symfony/twig-bundle": "^4.0", // v4.0.4
"symfony/web-server-bundle": "^4.0", // v4.0.4
"symfony/yaml": "^4.0" // v4.0.14
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.0", // 3.0.2
"easycorp/easy-log-handler": "^1.0.2", // v1.0.4
"fzaninotto/faker": "^1.7", // v1.7.1
"symfony/debug-bundle": "^3.3|^4.0", // v4.0.4
"symfony/dotenv": "^4.0", // v4.0.14
"symfony/maker-bundle": "^1.0", // v1.4.0
"symfony/monolog-bundle": "^3.0", // v3.1.2
"symfony/phpunit-bridge": "^3.3|^4.0", // v4.0.4
"symfony/stopwatch": "^3.3|^4.0", // v4.0.4
"symfony/var-dumper": "^3.3|^4.0", // v4.0.4
"symfony/web-profiler-bundle": "^3.3|^4.0" // v4.0.4
}
}
16 Comments
Hey there, now I am curious.. How to handle it in high traffic web projects :) ? At least as conceptual. Thanks.
It's a bit weird that it's not part of the tutorial since this is so important. I assume you need to write your own query to handle it so that it does an update and reads the current counter in a single query instead of separately, then theoretically there shouldn't be any race condition. You can use Doctrine's DQL for that, though I'm not sure where to put this query, inside the Entity?
Hey Anon,
Well, that's kinda performance and highload issue, this tutorial is not about it :) And it may depends on the query, so difficult to say. But all your queries are better to put into entity repository.
Cheers!
The query would be pretty simple, just something like
UPDATE App\Entity\Article u SET u.heartCount = u.heartCount + 1 WHERE u.id = :article_id.But since this is an update query, and all the examples in this tutorial are select queries, and all updates to entities seem to be done within entities I'm not sure what the proper place for an update query is. Maybe something to mention in the tutorial? Cheers for the response, I thought this comment would get lost since the other comments are a year old.
Hey there!
I think you can just place that query inside the corresponding repository class
Cheers!
One question, I want to log the last 10 "search requests" of a search form from my userbase, to output them on the main homepage.
What would you recommend to output only the newest 10 search requests?
To create an entity and:
1.) Create a db record for every search request and "clear" the table every 24h via a Cronjob?
2.) To use the update function (like in this tutorial) to update the "oldest" (of the 10) dataset in the DB?
3.) Or is there another, better approach?
I'm asking this because it seems to put a lot of stress on the system if a lot of search query get performed in the future simultaneously.
Thank you in advance!
Hey Mike P.
I wouldn't rely on the database for that feature because of what you said. It will increase the resources usage of the server (Unless you don't expect high traffic). The first thing that comes to my mind is to use Google Analytics to track all the searches performed and then consume their API to get a list of the searches, and cache the result for 10 minutes or so.
There might be better tools for what you want to do that I'm not aware of, so I recommend you to investigate a little bit before jumping to the implementation
Cheers!
Hey, after i make the changes and click the heart i get the following error.
No route found for "GET /news/this-is-my-article-10721/heart": Method Not Allowed (Allow: POST)
I'm on Symfony 4.4 , do i need to configure the route ?
Hey Robert
Looks like your route configured properly, looks like your ajax request not working, probably you may have errors in your browser console, can you check it?
Cheers!
Hi,
I don't understand how to change property of entity and how to fully delete entity with its migration?
Hey Oleksii V.
To fully delete an entity what you need to do is first delete the entity class file, and then create a migration that will DROP the related table of the entity
To change a property the flow is basically the same, you have to add a new property to the entity (add its metadata), and then create a migration that will update its table
I hope it helps. Cheers!
Thank You!
The code of the function setHeartCount get a heartCount parameter, but then calling in the controller without arguments. I suppose, that in the entity it should be like this:
Ah, it's not about the method, it's about the code highlighted for the video (setHeartCount instead of incrementHeartCount).
Hey toporovvv
Nice catch! Those code blocks were totally wrong, I've already fixed them :)
Have a nice day
Hello weaverryan , you just forgot to return $this in the incrementHeartCount method of Article Entity. In the code, not on the video :)
Cheers
Hey abdouniabdelkarim
Thanks for informing us! I already fixed it :)
Have a nice day
"Houston: no signs of life"
Start the conversation!