I am creating an 'award' system for my website to encourage a community fealing, much in the same way that stack overflow uses badges.
The site is built in CakePHP, i have created an Award model, controller etc - currently the methods for calculating whether a user has an award are contained 开发者_JS百科within the Award controller.
However, i can't decide on the best way to update awards - say for example, you make a certain number of comments and receive an award for this, CRON wouldn't be sufficient otherwise the user might visit their profile expecting an Award and not have one until the CRON is run.
I was thinking of using requestAction() to call the method to update awards in the Award controller however this doesn't really fit the MVC design pattern and thought there must be a better way!
If the only way to get an award is through making a comment, I'd just override Model::save to determine if it's a new comment being added. If it is, make a call to the awards model to update the award.
If there are multiple actions that can give awards, you could either tap into each model to perform this check, or modify AppModel so that every save results in a call to checkNewAwards()...
Or perhaps I'm not understanding the question?
create a function in the helper and put it in your layout so it runs every time the layout is rendered.
精彩评论