Reputation: 374
I'll be coding up both to test them, but I was curious on first blush what the folks here thought.
I've got an array of data that has been posted to my shopping cart controller. The array includes an entry for each of the product's potential options.
To get the options into an array for presentation I can either parse the array looking for arrays with keys that begin with "options-" or I can make a database call and find out what options are available for that product.
We are talking about at most 5 items at this time.
Thoughts?
Upvotes: 1
Views: 107
Reputation:
Pros of Hard coding
Cons of Hard Coding versus DB call
Upvotes: 0
Reputation: 163603
I think the keyword here is that the data is POST-ed to your controller.
You should never trust user data. Always verify user data with real data. So, if a user adds something to a shopping cart, make sure you go back to your database and ensure that what was added really does exist. Since you will be making the query at that time, best to rely on the data from your database.
Otherwise, data you already have in memory is certainly faster than going to a DB. Typically, you want to avoid making additional queries that are not needed.
Upvotes: 3