By Stephen Scholtz on
Hey there,
Quick q for the experienced Drupal devs out there...I'm using CCK (6.x-2.6) and have a text field using the radio/checkbox widget. I know you can supply "key|value" pairs for the options, so you can display the value as a label, but the key is the value stored in the database.
Any best practices on what format the "key" should take? Should the "value" be human-readable, while "key" is machine-readable (say, the value in camel-case or something)? Or should I even bother with the "key"?
I thought I remember reading something somewhere that providing a good (or just any?) "key" is essential for multi-lingual sites 'n string translation?
Thanks for your help!
Stephen
Comments
Good Question...Hope someone
Good Question...Hope someone can answer.
The key is usually just more terse, in my experience...
I think it's best to have keys that are still human-parsable in the database. If you have a lot of options, providing numeric keys, for instance, can just be confusing. But it's better not to store all the longer keys in the DB, if you can use shorter codes that are easy to understand when looking at the DB dump, etc. For instance, you might use:
And that makes sense (common boolean values).
Or you might use abbreviations for U.S. states or for countries, e.g.:
The *key* is *not* translated, just the label displayed in the interface could be. The keys are not going to be table names or anything so it really doesn't matter what they look like as long as they are short and still understandable, just in case you ever have to migrate your database tables or something and need to know what the hell all those keys mean. ;-)
If your terms are already short, there's no real need to use a key|Label pair... you can use the same for both and it's really no big deal. If all your keys are 2-character codes, for instance, in theory you can make your database storage for that field smaller; but that's not as big an issue now as it was some time back. I've noticed Drupal tends to be a bit wasteful compared to what I'd do if I were writing the tables myself.
HTH
See you at the Drupalcon!
Thank you. your answer was
Thank you. your answer was very helpful.
No problem; glad to help. :-)
No problem; glad to help. :-)
See you at the Drupalcon!