I'm having a design problem inside my Zend app and I don't really see where I should plug this feature to have a design integrated correctly inside Zend Framework.
What I want is to displayed inside every public page of my app some stats like the count of entries in the database (like the number of users). I need to have a dedicated function to do this computation since I want to cache its result.
I've to add that part of my actions are acting as JSON REST ressources (for AJAX purposes) while others behave like common HTML dynamic pages (thus setting an object in all views object isn't perfect).
I'm thinking about the following solutions :
- Adding a controller plugin that would be setting an object containing my stats values inside the Zend_Registry, this plugin would handle the cache
- Adding inside my models a function enabling the computation of those stats. This would imply that the feature would be exploded over all my models (which is not really a clean design), these models will cached some values (which is not their job TMHO) and this will make these computations trigger by the view (I usually let the controller load the value inside the view)
Does anyone has any suggestions or comments about a cleaner solution ?
My criterions are :
- Integration in Zend Framework design philosophy
- Respect of model integrity (a cache value means an inexact value)
- Avoiding of workarounds like using static ressources like Zend_Registry
ajaxContextSwitcherwould parse it to JSON, and helper will just loop over the stats. - Bartosz Grzybowski