Welcome Guest, Not a member yet? Register   Sign In
Handling custom collection of different fieldtypes (in CRUD structure)
#1

[eluser]Mr. Pickle[/eluser]
I'm building an app and I want users to be able to generate their own 'modules'.
In this case a module is a collection of one or more fields with their own type that corresponds to the database field it's value is stored in.

Let's say the user can choose between the following types:
- text (text) / <textarea>
- text (var char) / <input type="text">
- number (int) / <input type="text">
- file (upload) / <input type="file">
- options (select) / <select>
- options (radio) / &lt;input type="radio"&gt;

To build the CRUD pages (CREATE, READ, UPDATE, DELETE) I need to build the form element per fieldtype.
I guess this is best done with a function per fieldtype passing parameters like the value (in case of update), possible choices (in case of a select dropdown), maxlength (in case of input text) etc, etc.

My question is how can I best manage the logic of how the form element are build within my CRUD pages.
Some idea's that crossed my mind.
1. Loop the array with all the fields in the view file and per chosen fieldtype call a helper, like build_inputtext(); build_select(); and pass optionally options (like maxlength, option values, value (in case of update))
2. Make a library that handles the fieldtypes (and have functions and own view files per fieldtype)
3. Making a module (I'm using the HMVC-functionality) per fieldtype

The base must be: using only one controller that handles every possible collection of fieldtypes a user in my system determines for his/her module.

I'm not looking for full solutions but more a direction to think in to keep it centralized, smart and easily maintainable and as scalable as possible.

Hope I explained my question in an understandable manner.

Thanks!




Theme © iAndrew 2016 - Forum software by © MyBB