Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialjlampstack
23,932 PointsReal life example?
Can anyone provide a real life example how this would be used? I don't think it's practical for someone who is sitting in front of their computer to have to type in all this code for each and every single recipe. For one recipe fine, but for 100 recipes??? It feels unnatural and like a lot of work.
How would this be used in the real world? Would the user enter the input into a form field?
$granola_muffins = new Recipe("Granola Muffins");
$granola_muffins->addIngredient("egg", 2);
$granola_muffins->addIngredient("sugar", .25, "Cup");
$granola_muffins->addIngredient("oil", .5, "Cup");
$granola_muffins->addIngredient("milk", 1, "Cup");
$granola_muffins->addIngredient("vanilla", 1, "tsp");
$granola_muffins->addIngredient("white vinegar", .5, "tsp");
$granola_muffins->addIngredient("granola", 2, "Cup");
$granola_muffins->addIngredient("flour", 1, "Cup");
$granola_muffins->addIngredient("instant protein", 4, "tbsp");
$granola_muffins->addIngredient("baking powder", 2, "tsp");
$granola_muffins->addIngredient("cinnamon", 2, "tsp");
$granola_muffins->addIngredient("baking soda", .5, "tsp");
$granola_muffins->addIngredient("salt", .5, "tsp");
I've asked this same question in an earlier video, but no reply. If anyone can answer it would be greatly appreciated.
Thanks in advance!
3 Answers
Alena Holligan
Treehouse Teacherjaycode you're right, typing is a pain ;) It has to be entered somehow, so for the first time it could very well be a form and then stored in some sort of data file like a database. Then there is Object-relational mapping (ORM) who's job it is to take the data from a database and map it to an object which you would then use in the same way as you are creating here :) In a small way that's what PHP Data Objects (PDO) are.
jlampstack
23,932 PointsAlena Holligan Hi Alena, Great PHP video series! Can you shed some light on how this would be used in a real life scenario?
jlampstack
23,932 PointsThank you Alena Holligan ! Is there a video series on how to do this?