It’s been quite a while since I last worked with Yii, so I’m mostly trying to get myself reaquainted again. I followed the blog tutorial again and I think I have a decent grasp on what is going on there. Now I am experimenting a bit with modules, and I have a scenario that I am not quite sure how to tackle.
I am currently writing a light-weight user module (I don’t want to use an existing one, as this is simply a good spare-time exercise project). The module should make it possible for a user to edit two user settings areas:
account settings (password, email, timezone, and so on)
profile settings (displayed name, age, and so on)
User settings and account settings are saved in different database tables and use different models. So far so good. But now the part that I am not sure about. The settings page for this user module so far only shows settings that apply to the user. But what if I want to allow the user to set some personal preferences specific to an application. More particular, settings that are to be used by other modules. I only program as a hobby, and I lack the knowledge so far on the best strategy to implement this (hoping to learn something here… )
My first thought was to make an IUserSettings interface that other application specific modules might implement. That interface would expose a getSettings() method that delivers an array with form configuration. The actionSettings method in the user module would then check each enabled module if it implements the interface (using instanceof), collect any form config from the interface implementations, combine them into a single form and render it.
Is this a step in the right direction? If so, how would you suggest I handle the different models the end-form needs to update for each form element? Are there better strategies? If so, any pointers? I’m not neccessarily looking for a fully written out example, but a general idea on a direction to start working from.