他のいくつかの質問を読んだ後、エンティティ クラスにリポジトリを使用させることはお勧めできないようです。したがって、これらのリポジトリを考えると:
class RestaurantRepository {
public function findAll() { ... }
}
class ReviewRepository {
public function findByRestaurant(Restaurant $restaurant) { ... }
}
クラスでこれを行うべきではありません:
class Restaurant {
public function getReviews() {
// ...
return $restaurantRepository->findByRestaurant($this);
}
}
しかし、ビューにレストランのリストを与えるこのコントローラーがあるとしましょう:
class IndexController {
public function indexAction() {
$restaurants = $restaurantRepository->findAll();
$this->view->restaurants = $restaurants;
}
}
ビュースクリプトで各レストランのレビューを取得するための「良い習慣」は何ですか? したがって、私はこれを行うことはできません:
foreach ($this->restaurants as $restaurant) {
$reviews = $restaurant->getReviews();
}
そして、ビューに ReviewRepository を挿入することも、「ベストプラクティス」とは言えないと思います...
どんなコメントでも大歓迎!