YII widget access model - I need a value from DB in my layout

176 Views Asked by At

In a layout I need to display number of notifications.

what is the right way of doing it? I'm thinking to create a widget for it but is accessing DB while rendering view correct?

1

There are 1 best solutions below

0
On BEST ANSWER

Yes, it is ok to create a widget for this needs.

After done, it is ok to call it from layout.

You can even use caching in order not to bother DB too often.

http://www.yiiframework.com/wiki/17/how-to-make-use-of-a-fragment-cache/

Finally: I would recommend writing widget and using it with fragmental caching.