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 Enhancing a Simple PHP Application Refactoring the Codebase Separating Concerns: MVC

Nthulane Makgato
PLUS
Nthulane Makgato
Courses Plus Student 19,602 Points

Separating Concerns MVC 4/4

Hi guys and girls,

I am struggling with a challenge. I think that there is a lot to copy but here is the basic information and the link to the challenge.

http://teamtreehouse.com/library/enhancing-a-simple-php-application-2/refactoring-the-codebase/separating-concerns-mvc

Since the flavors are now ordered by the number of likes, it would be nice to display the number of likes next to each flavor. Instead of showing just the flavor name ("Cookie Dough"), change it to show the flavor name, followed by a space, followed by a plus sign, followed by the number of likes ("Cookie Dough +976"). (Look through flavors.php to see the structure of the flavors array and to figure out how to access the number of likes.)

<?php

// INCLUDE MODEL FILE
require_once("flavors.php");



// CONTROLLER CODE
$flavors = get_flavors_by_likes(3);

foreach ($flavors as $flavor) {
  echo "<li>" $flavor["name"] . "+" . $number
}


// VIEW CODE
?><html>
<body>

    <h1>Ye Olde Ice Cream Shoppe</h1>

    <p>We sell amazing flavors of ice cream.</p>

    <h2>Most Popular Flavors</h2>

    <ul>
    <?php
        foreach ($flavors as $flavor) {
           // echo "<li>" . $flavor["name"] . " " . "+" . $flavor["likes"] . "</li>";
          echo "<li>" . $flavor["name"] . " +" . $flavor["likes"] . "</li>";
        }

    ?>
    </ul>

</body>
</html>

The commented out section and the line below are the codes that I have tried but don't work.

Thanks in advance.

1 Answer

Hi Nthulane,

I think that either one of your statements should work although the second one is probably preferred.

You're trying to echo out some list items in your controller code section which isn't part of the challenge. I think this is throwing it off. Remove that code and you should pass.