Answer the question
In order to leave comments, you need to log in
What is the correct way to display the number of unread messages in yii2?
Hello.
Tell me how to do it right.
There is a small chat, messages are stored in the database.
There is a place in the header where you need to display the number of unread messages (the header is located separately in the layout).
I can only imagine such an implementation, in each controller we make a request to the database and display it in the layout.
But this will have to duplicate the code in each controller.
Answer the question
In order to leave comments, you need to log in
Option 1:
In the application config
'on beforeAction' => function(){
//Ваш код который будет работать перед любым экшеном
},
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question