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 trial

PHP

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

[SOLVED] Building the Cookbook example into a website.

Okay, so what I have is a website with the PHP Cookbook example which I'm trying to expand so I can use it as a portfolio piece. But I'm out of my depth here.

I have all the code working from the cookbook.php file but when I try to migrate the code I keep getting errors.

For example in recipelist.php I have a call to Render.php that outputs the recipe titles for each one in cookbook.php. But when I move it to this file I get the following error.

<h1>Cookbook: Recipes by Alena Holligan and Ken Alger</h1>

    <p>These recipes were curated from a list of recipes that are instances of the PHP Object class.</p>
    <?php echo Render::listRecipes($cookbook->getRecipeTitles()); ?>
Fatal error: Class 'Render' not found in C:\xampp\htdocs\treehouse\php\php-cookbook\recipelist.php on line 13```

And in another case, in shoppinglist.php I have the following errors

Notice: Undefined variable: cookbook in C:\xampp\htdocs\treehouse\php\php-cookbook\shoppinglist.php on line 17

Fatal error: Call to a member function getCombinedIngredients() on null in C:\xampp\htdocs\treehouse\php\php-cookbook\shoppinglist.php on line 17

```php
<?php  

            $week1 = new RecipeCollection("Meal Plan: Week 1");

            $breakfast = new RecipeCollection("Breakfast");
            echo "<br /><br />Based on the recipes currently in the Cookbook, you'll need to shop for the following ingredients... <br />";
            echo Render::listShopping($cookbook->getCombinedIngredients() );
            //echo Render::listShopping(getCombinedIngredients() );

?>

But what I don't understand is why I can't make these migrations to another file if I'm using includes. What they do as I recall is act as a "copy and paste" for code from one file into another... shouldn't it be picking up arrays and variables so I can add say the "meal plan" to one page and a shopping list to another?

I have the elements to the site that I need, I just want to separate them into different files/pages.

1 Answer

Matthew Smart
Matthew Smart
12,567 Points

We would need more code to check, I dont know what cookbook.php is either to help. IF your still stuck please leave more information and ill try to help

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,253 Points

Hi Matthew,

Thanks for this. I have to say that since then I have solved most of the errors I found in the site and while I still have a lot to learn I'm getting close to the website I wanted to build :)

In this case, most of the problems I had were because I missed out an important include file where the variables were being stored. I've since been able to partition the appropriate echoes to the right pages.

Solved for now :)