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 Object-Oriented PHP Basics Building the Recipe Separating Methods

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

listIngredients function not showing up on output

Hi there,

in the same vein as my post yesterday I'm having some trouble with my output to HTML file though I'm not sure what the difference is between console and HTML .

I've followed the video, separating the foreach loop into it's own method but nothing shows up.

Any idea what I'm missing? Thanks

render.php
<?php

class Render {


            public static function listIngredients($ingredients) {

                $output = "";

                //Since Ingredients have their own variables in their array, we need to use a foreach loop to retieve them.
                foreach($ingredients as $ing) {
                     $output .= $ing["amount"] . " " . $ing["measure"] . " " . $ing["item"];
                     $output .= "<br />";
                 }

                 $output .= "<br />";
                 return $output;

            }

            /*display Recipe method*/           
            public static function displayRecipe($recipe) {

                $output = "";  
                $output .= "<br /> ";   
                $output .= "Recipies";
                $output .= "<br />---------<br />";
                $output .= $recipe->getTitle() . " by " . $recipe->getSource();
                $output .= "<br />";
                $output .= self::listIngredients($recipe->getIngredients() );
                $output .= implode(", ", $recipe->getTags());
                $output .= "<br />";        

                /*<br /> for new line when outputting to a html file.*/
                return $output;

            }
}

?>
cookbook.php
<?php

class Render {


            public static function listIngredients($ingredients) {

                $output = "";

                //Since Ingredients have their own variables in their array, we need to use a foreach loop to retieve them.
                foreach($ingredients as $ing) {
                     $output .= $ing["amount"] . " " . $ing["measure"] . " " . $ing["item"];
                     $output .= "<br />";
                 }

                 $output .= "<br />";
                 return $output;

            }

            /*display Recipe method*/           
            public static function displayRecipe($recipe) {

                $output = "";  
                $output .= "<br /> ";   
                $output .= "Recipies";
                $output .= "<br />---------<br />";
                $output .= $recipe->getTitle() . " by " . $recipe->getSource();
                $output .= "<br />";
                $output .= self::listIngredients($recipe->getIngredients() );
                $output .= implode(", ", $recipe->getTags());
                $output .= "<br />";        

                /*<br /> for new line when outputting to a html file.*/
                return $output;

            }
}

?>

2 Answers

Hazem mosaad
Hazem mosaad
15,384 Points

Can I see the cookbook.php file and recipes.php So I can help thanks :)

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,253 Points

Both files are in my post but thanks anyway, I was able to resolve this particular post! :)

Hazem mosaad
Hazem mosaad
15,384 Points

Great To here that but you upload render file twice :)