When im using model in Layout directly or through widget yii2 refreshes page twice

I need to show unread messages in menu in main layout menu. When im using model in main.php layout (for example use yii\models\User; and in body <?php User::find(1); ?>) i found that page will be reloaded twice (first: then i open url forexample www.x.com/user/dashboard second: just reloaded ) . If i remove User::find(1); then page will be rendered only once! Same thing then i use widget and call User::find(1); inside widget. But page will continuesly reloaded twice.

Can anybody help ?

Reloaded twice or rendered twice?

yes, reloaded automatically and as a result it is renders main.php (layout). I don’t know why model usage in layout makes this happen.

That’s not what Yii does out of the box but something in the application itself.