Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
      You have completed Object-Oriented PHP Basics!
      
    
You have completed Object-Oriented PHP Basics!
Preview
    
      
  Now that we have our recipe class complete, we’ll create all the recipe objects for our collection.
Ways to pull the recipes
- Typed straight into code (single or individual files)
- Read from individual text files
- Stored in a Database
- Pulled from an API / JSON feed
Note: This course uses option 1 with a single file.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
                      I hope you enjoyed exploring
your magical powers so far.
                      0:00
                    
                    
                      In the words of Terry Pratchett,
it's still magic,
                      0:04
                    
                    
                      even if you know how it's done.
                      0:07
                    
                    
                      We still have more to learn.
                      0:09
                    
                    
                      In the next section, we'll be
grouping our objects into collections
                      0:10
                    
                    
                      by creating a cookbook for our recipes.
                      0:14
                    
                    
                      To do that,
we'll need some recipes to work with.
                      0:17
                    
                    
                      Plus, I promised you
some of my own recipes.
                      0:20
                    
                    
                      So how do we load up
a bunch of recipe objects?
                      0:23
                    
                    
                      There are many different ways
to load these recipes or
                      0:27
                    
                    
                      any other data into our program.
                      0:30
                    
                    
                      Most likely, you would want to
use some sort of database or
                      0:32
                    
                    
                      pull from a json feed or
something similar.
                      0:36
                    
                    
                      Data storage and feeds are more than
we need to get into in this course.
                      0:39
                    
                    
                      So instead I set everything up for
you in a single recipe.php file.
                      0:44
                    
                    
                      Grab that file from the download section,
and
                      0:49
                    
                    
                      let's get some recipes
loaded into the project.
                      0:52
                    
                    
                      We want to stay organized.
                      0:55
                    
                    
                      Since this is a helper file,
we want to put it in a new folder.
                      0:57
                    
                    
                      So let's add a new folder called inc.
                      1:01
                    
                    
                      This is short for include.
                      1:06
                    
                    
                      Then we'll upload the recipes.php file.
                      1:09
                    
                    
                      Let's take a look at this recipes file.
                      1:17
                    
                    
                      At the top, I've included a DocBlock
comment area that gives you some notes,
                      1:21
                    
                    
                      as well as a list of all
the recipes in this file.
                      1:26
                    
                    
                      You can scroll down and
                      1:29
                    
                    
                      see these recipes have been added
just like we added recipe1.
                      1:30
                    
                    
                      You're welcome to add your own
recipes to this file as well.
                      1:34
                    
                    
                      Let's load these recipes into our project.
                      1:39
                    
                    
                      Back in cookbook.php,
we'll add a new include.
                      1:42
                    
                    
                      And voila,
you have a bunch of recipes ready to use.
                      1:53
                    
                    
                      Let's clean up the recipes
from this file and
                      1:57
                    
                    
                      display one of the full recipes
from this new file instead.
                      1:59
                    
                    
                      Now let's run this script.
                      2:15
                    
                    
                      Great, we see our Belgian waffle
recipe by Alena Holligan.
                      2:23
                    
                    
                      All this work is making me hungry but
                      2:28
                    
                    
                      we're not quite ready
to start cooking yet.
                      2:31
                    
                    
                      You're doing great.
                      2:34
                    
                    
                      We have a recipe class and
all our recipe objects loaded.
                      2:35
                    
                    
                      We have a render class for rendering
our recipes in the desired formats, and
                      2:40
                    
                    
                      we've taken on the role of magician.
                      2:45
                    
                    
                      That's quite the accomplishment.
                      2:47
                    
                    
                      At this point our recipes
are basically a random stack of cards.
                      2:49
                    
                    
                      That makes it really hard to find
anything we actually want, or
                      2:53
                    
                    
                      even to know what we have.
                      2:58
                    
                    
                      In the next section,
we'll create a collection of objects
                      3:00
                    
                    
                      that can help us organize and
make use of these recipes.
                      3:03
                    
                    
                      Man does not live on coding alone,
so take a break and recharge.
                      3:07
                    
                    
                      But hurry back, I'm excited to
show you my cookbook collection.
                      3:11
                    
              
        You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up