manage module's options approach
Question by mhesabi
I’m about to create let say a custom CMS with php and mysql. each page has a few zones. each zone can output modules. for example we have a news module and we already added news categories and single news items at module admin section.
but here it begin: end user wants to get different output of this module. for example user wants to show news of “sport” category, or user wants to show top 5 last news, or user wants to sort news by something, or, or, or …. many other options that a module can take.
my question is what is your solution to handle and manage these options.
– do you suggest a module_option table for every module like news_options?
– do you suggest a single table that holds every modules options?
hope I could get what i mean 😉 also let me know if db diagram is necessary.
Answer by Starx
-
First approach could be using different table for each module. Then you can keep the settings of different instance in the fields. In the manageable form.
Example:
Table: News ---------------------------------------------------------------------- | id + news_title + option 1 + option 2 | ----------------------------------------------------------------------
-
Next approach, could me using Global configuration table, which holds the key name and one field and key value in another field. This way you dont have to create different table from different modules.
Example:
Table: ModuleOption
--------+-----------------+-------------------+---------------------+ | id | module_id | setting_name | settings_value | --------+-----------------+-------------------+---------------------+ | 1 | 1 | option 1 | option value 1 | --------+-----------------+-------------------+---------------------+ | 2 | 1 | option 2 | option value 2 | --------+-----------------+-------------------+---------------------+
The questions about which one to choose over which, depends on how you code your project. Both have its own advantages and disadvantages. However, some points to consider
- If the option contains a method to input long text then, second approach is bad as the size of options will vary a lot.
- If all the module settings can accompany with in fixed length fields, then second option is definitely the best way.