JMSシリアライザとFOSRestBundleの設定に問題があり、このカスタムリポジトリメソッドをシリアル化しています。JMSシリアライザがFOSRestのカスタムリポジトリメソッドで動作しない
私は$schedules = $em->getRepository('RadioBundle:Schedule')->findAll();
を使用しても問題なく動作しますが、カスタムメソッドを試してみると、どのフィールドも除外されません。
誰かが間違ったことを解決するのに手助けできますか?
コントローラー:
use RadioBundle\Entity\Schedule;
use Symfony\Component\HttpFoundation\Request;
use FOS\RestBundle\Controller\Annotations\View;
class ScheduleController extends BaseController
{
/**
* @param $date
* @return \Symfony\Component\HttpFoundation\Response
* @View(serializerGroups={"schedule"})
*/
public function getSchedulesScheduleAction($date)
{
$em = $this->getDoctrine()->getManager();
list($startDate, $endDate) = $this->get('radio.utils.date_and_time')->findWeekRange($date);
$schedules = $em->getRepository('RadioBundle:Schedule')->findByRange($startDate, $endDate);
$view = $this->view(
[
'schedules' => $schedules,
],
200
);
return $this->handleView($view);
}
}
リポジトリ方式:
class ScheduleRepository extends EntityRepository
{
/**
* @param \DateTime $startDate
* @param \DateTime $endDate
* @return array
*/
public function findByRange(\DateTime $startDate, \DateTime $endDate)
{
$em = $this->getEntityManager();
$qb = $em->createQueryBuilder();
$qb->select('s')
->from('RadioBundle:Schedule', 's')
->leftJoin('s.radioShow', 'rs')
->add(
'where',
$qb->expr()->between(
's.startTime',
':from',
':to'
)
)
->orderBy('s.startTime', 'asc')
->andWhere('rs.isActive = true')
->setParameters(['from' => $startDate, 'to' => $endDate]);
return $qb->getQuery()->getArrayResult();
}
}
シリアル化が動作するには、配列ではなく実体が必要です。あなたの問題の解決策である@martin answerをチェックしてください。 – malcolm