I have the problem, that I have two controllers. One is a restful controller which only handles json
data and returns a JsonModel
, and the other one is a default controller which returns a ViewModel
Now I have the problem, that my method only returns an array
of entities, which is correct for the default controller, but my restful controller needs the entities as an array. How can I handle this?
MealController
class MealController extends AbstractRestfulController {
protected $mealService;
public function getList() {
$meals = $this->mealService->getAllMeals();
return new JsonModel($meals);
}
}
MealService
class MealService {
protected $mealRepository;
public function getAllMeals() {
return $this->mealRepository->findAll();
}
}
MealRepository
class MealRepository extends EntityRepository {
public function findAll() {
$queryBuilder = $this->createQueryBuilder('meal')
->orderBy('title');
return $queryBuilder->getQuery()->getResult();
}
}