I have a table "notification_types" (id, type, name).
The table consists of the next rows:
comment_photo
comment_comment
vote_photo
vote_comment
…
comment_article
I want to create a form based on this rows. I want to let users to choose notifications (via checkboxes) they want to receive.
In perfect in my model I would create a method named something like "setNotificationFields", which would get data from a database and dynamically create properties of the object with validators and labels without need to manually declare public properties of each type of notification. Is it possible?
Why don’t you maintain all those rows in the database as boolean and use checkboxes to set/reset? And if you need to work on, work with only the set boxes. Would this be your solution?
At first that was my solution, but I thought that it would be better if I will not depend on DB schema. Now I’m starting to think about database storing this values as columns again, otherwise it seems to require hacks.
Reza m, your example is exactly how I was thinking. But I can’t find a way to create form dinamically. Having table “notification_type” I will need to build rows of checkboxes with attributes name and label retrieved from database. I could create all needed fields-properties right in form, but I think it’s hacky.
by looking at Collecting Tabular Input article your path is clear, for example you can create an array of notification results models in controller and send them to view then create your form and collect results from user