Scenario:
3 tables:
restaurants
cuisines
features
2 join tables:
cuisines_restaurants
features_restaurants
Question:
What is the best way to get data for a single restaurant from my controller to the view which includes not only the restaurant data, but also the cuisines and features that it has.
I have it working with this:
$restaurant = $this->Restaurant->find('all', array('conditions' => array('Restaurant.id' => $id)));
$this->set('restaurant', $restaurant);
And I'm calling it in the view like this:
echo "<span class='label'>Name:</span> " . $restaurant[0]['Restaurant']['name'] . "<br />";
echo "<span class='label'>Cuisine:</span> ";
$cuisineList = "";
foreach($restaurant[0]['Cuisine'] as $cuisine) {
$cuisineList .= $cuisine['name'] . ", ";
}
echo substr($cuisineList,0,-2) . "<br />";
(and repeat for Features)
But this seems overkill, since in all the Cake tutorials I see, the view method in the controller just has:
$this->set('restaurant', $this->Restaurant->read(null, $id));
Then they call it like this:
echo $restaurant['Restaurant']['name'];
...etc
Again - it IS working - I just want to know if there's a better way - the way I'm currently doing it seems sloppy compared to all the other slick things Cake does for me! :)