Welcome Guest, Not a member yet? Register   Sign In
Where do you store dropdown option data?
#1

[eluser]jleequeen[/eluser]
Hello Everyone,

I'm working on some drop down option lists using the form_dropdown helper. For some fields I just need a simple Yes/No, but for other list options I need to pull them from a table in the database. I also have a few dropdowns that have anywhere between 5-10 options. What I'm wondering is where does everyone store their dropdown data? Pulling a list of states is easy because that would come from a states table in the database. But what about those Yes/No/Maybe options. What about pull downs with a handful of options. Obviously it would probably be overkill to create tables for lists with so little options. Does anyone code these into a model that is only for dropdowns data?

Thanks in advance.
#2

[eluser]Damien K.[/eluser]
If you want the most flexibility at the expense of development time, you pull all data from your model. Then the model will pull the data from a datasource, file, xml, rpc, web service, or hard-coded.
#3

[eluser]wabu[/eluser]
I think an important consideration is how often a list changes. If it's relatively static then maybe it doesn't need to live in a database, regardless of length.

For example, I've stored U.S. states in tables before too but realistically, when is that going to change?
#4

[eluser]Damien K.[/eluser]
Hard-coded (ie, an array) for short list in the model. Quick and efficient. Refactor in the future if necessary.

I would pull data from the database for states. If performance is a concern, then I would cache the model->get_states() function.
#5

[eluser]pmoroom[/eluser]
[quote author="Damien K." date="1253340203"]Hard-coded (ie, an array) for short list in the model. Quick and efficient. Refactor in the future if necessary.

I would pull data from the database for states. If performance is a concern, then I would cache the model->get_states() function.[/quote]

I would store in a database if you plan to provide additional options in the future. I pull from a database if I plan on allowing the admin side of my code to modify the data. So, most in my application are from a database with an admin section to add/remove etc.
#6

[eluser]Colin Williams[/eluser]
Nothing is "static" but there are occasions where something is sort of static, like states, colors, etc. Store these in a configuration file, serve it via the model using the config class.
#7

[eluser]jleequeen[/eluser]
[quote author="Colin Williams" date="1253342075"]Nothing is "static" but there are occasions where something is sort of static, like states, colors, etc. Store these in a configuration file, serve it via the model using the config class.[/quote]

Could you explain how you use the config class as you suggested?
#8

[eluser]Colin Williams[/eluser]
I don't think I could explain it any better than the user guide does. Check out the config class page




Theme © iAndrew 2016 - Forum software by © MyBB