K
K
kranopodem2016-05-02 12:47:20
Yii
kranopodem, 2016-05-02 12:47:20

YII2 Maintaining statistics using database queries. Where, how, where?

Hello. I have such a question. If, somewhere on the site, statistics are kept, using queries to the database, for example, "SELECT COUNT (*) FROM pet". Where is it best to write it, in the controller, or somewhere in the model to come up with something.
In theory, there should be a similar sign, it will be displayed on all pages of the site:
OChfFQX.png
It seems to me that this will cause too many queries to the database, how can all this be optimized?
Thanks in advance for your replies.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Bukharev, 2016-05-02
@kranopodem

If the sign will be displayed on all pages of the site, then we create a widget, and put the functionality for displaying the sign in it, then we write queries to the database, you can also configure caching for these queries, for example, by time. We place the widget call code in the necessary places! Profit!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question