P
P
Pogran2016-07-06 09:12:49
Yii
Pogran, 2016-07-06 09:12:49

How not to pull from a DB constantly a role of the user?

I have in different parts of the code (in different parts of the view, in the controller, in models) there are such checks for the user's role.
Yii::$app->getUser()->can("provider")
That is, we check if the user has view rights. This in turn generates a query to the database, which is very bad. It takes me up to 8 requests from different parts of the code to check user rights to the database. www.prntscr.com/bpdphc . How to correctly check the user's role so as not to pull it from the database all the time. I have rbac on my site with saving roles in the database. I also store the user role in the user table in the role field (for convenience).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Максим Федоров, 2016-07-06
@Pogran

для того что бы не дергать каждый раз данные из базы, можно включить кеширование для rbac

'authManager' => [
    'class' => 'yii\rbac\DbManager',
    'cache' => 'cache',
    'cacheKey' => '9kfs0kl,
],

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question