Central Calculation "Controller" - Design Question

Hei All

I’ m programming a Webapp with Yii that has some central calculation (read database, calculate some things, update database) per User some should be done in “realtime”, meaning I didn’t consider cronjobs as part of the solution.

Whenever a user reloads any site of my application, I need to read some stuff from the database, do some calculation with it and update the database and afterwards present the result to the user. Its supposed to happen in every controller, so that I can present the calculated data on every page of my site to the user.

My approach for a solution was a “Central Controller” which is preloaded in the main.php configfile of Yii. Then I’m calling that central calculation controller in every other controllers “constructor” function so that I don’t have to call it in every action method, just once per controller.

That is working as expected but I don’t know if there is a better solution with Yii and the following problem arises.

The user can change what data should be read from the database but I can’t catch $_GET variables from the users input in a constructors method, or can I?

What would be a better approach for such a central calculation which is part of every controller without having to call it repeatedly from each controller?

That’s what Active Record is for.

A good candidate for a widget which should be included in your main layout. Database operations can be triggered in the run() method of the widget, then you can render the result as you would do it in a controller.