R
R
rrolegov2017-09-19 19:59:43
Yii
rrolegov, 2017-09-19 19:59:43

What is better - to use a session or to query the database?

Good afternoon, I want to consult a little on this issue. In Yii2, I have a page section on a site that is available to users who have not only registered but also verified their email. For those who have not confirmed their email, this section on the page is not available, although the page itself is available. The page itself is rendered in the controller, which passes the user_status parameter (0 - unregistered, 1 - registered, 2 - confirmed email) to the view of this page. Accordingly, depending on the value of user_status, view either shows this hidden section or closes it. The question that worries me is that every time the action is called, the controller must pass to the view user_status, so the controller makes a request to the database and receives information about the current user. Yii->app-> I can't use user-identity here, because my logic is not part of the IdentityInterface, so the user component does not contain the information I need. But is it reasonable to access the database every time? Or would it be more correct to put the user's status in the session? Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
xmoonlight, 2017-09-19
@xmoonlight

Or would it be more correct to put the user's status in the session?
This option is correct, because no need to constantly pull the base.
PS: In general, you need to have a parent class repository in the application and get all the necessary data about the user from the database or session there once for the entire time the script is running (for one client request via URL) ...
For the future, for the session cache :
1 The session is the caching of the database data.
2. Request to the database - updating the cache data.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question