FullCalendarBundle在symfony 3.4中安装后显示错误

时间:2018-07-16 17:21:19

标签: symfony fullcalendar

我安装了fullcalendarbundle,并按照Github所述配置了它,但是当我运行它时, 除了[null,null]之外,屏幕上什么都没有显示:

或者它应该向我显示一个日历,我可以在其中添加事件并将其保存在数据库中。

这是我的听众:

namespace Doctix\MedecinBundle\EventListener;

 use Doctix\MedecinBundle\Entity\Schedule;
 use Toiba\FullCalendarBundle\Entity\Event;
 use Toiba\FullCalendarBundle\Event\CalendarEvent;

 use Doctrine\ORM\EntityManagerInterface;
 use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

class FullCalendarListener
{
/**
 * @var EntityManager
 *
 */
private $em;

/**
 * @var UrlGeneratorInterface
 */
private $router;

public function __construct(EntityManagerInterface $em, UrlGeneratorInterface $router)
{
    $this->em = $em;
    $this->router = $router;
}
  /**
 * @param CalendarEvent $calendar
 */
public function loadEvents(CalendarEvent $calendar)
{
    $startDate = $calendar->getDateDebut();
    $endDate = $calendar->getDateFin();
    $filters = $calendar->getFilters();

    // You may want do a custom query to populate the calendar
    // b.beginAt is the start date in the booking entity
   $schedules = $this->em->getRepository(Schedule::class)
        ->createQueryBuilder('s')
        ->andWhere('s.date_debut BETWEEN :date_debut and :date_fin')
        ->setParameter('date_debut', $startDate->format('Y-m-d H:i:s'))
        ->setParameter('date_fin', $endDate->format('Y-m-d H:i:s'))
        ->getQuery()->getResult();

    foreach($schedules as $schedule) {

        // create an event with the booking data
        $scheduleEvent = new Event(
            $schedule->getTitle(),
            $schedule->getDateDebut(),
            $schedule->getDateFin() // If end date is null or not defined, it create an all day event
        );

        $scheduleEvent->setUrl(
            $this->router->generate('schedule_index', array(
                'id' => $schedule->getId(),
            ))
        );

        /*
         * For more information see : Toiba\FullCalendarBundle\Entity\Event
         * and : https://fullcalendar.io/docs/event-object
         */
        // $bookingEvent->setBackgroundColor($booking['bgColor']);
        // $bookingEvent->setCustomField('borderColor', $booking['bgColor']);

        // finally, add the booking to the CalendarEvent for displaying on the calendar
        $calendar->addEvent($scheduleEvent);
    }
}

} 这是我的实体:

    namespace Doctix\MedecinBundle\Entity;

    use Doctrine\ORM\Mapping as ORM;

  /**
  * CalendarEvent
  *
  * @ORM\Table(name="schedule")
  * 
  )
 */

class Schedule
 {
  /**
  * @var int
  *
  * @ORM\Column(name="id", type="integer")
  * @ORM\Id
  * @ORM\GeneratedValue(strategy="AUTO")
  */
 private $id;
  /**
  * @var string
  *
  * @ORM\Column(name="title", type="string", length=255)
  */
  private $title;
  /**
  * @var \DateTime
  *
   *@ORM\Column(name="date_debut", type="datetime", nullable=true)
   */
  private $date_debut;
  /**
  * @var \DateTime
  *
  *@ORM\Column(name="date_fin", type="datetime", nullable=true)
  */
   private $date_fin;

  /**
  * @ORM\ManyToOne(targetEntity="Doctix\MedecinBundle\Entity\Medecin")
  * @ORM\JoinColumn(nullable=true)
  */
 private $medecin;


/**
 * @return int
 */
public function getId()
{
    return $this->id;
}
/**
 * @param int $id
 */
public function setId($id)
{
    $this->id = $id;
}
/**
 * @return string
 */
public function getTitle()
{
    return $this->title;
}
/**
 * @param string $title
 */
public function setTitle($title)
{
    $this->title = $title;
    return $this;
}

/**
 * @return \DateTime
 */
public function getDateDebut()
{
    return $this->date_debut;
}
 /**
 * @return \DateTime
 */
public function getDateFin()
{
    return $this->date_fin;
}
/**
 * @param \DateTime $date_debut
 */
public function setDateDebut($date_debut)
{
    $this->date_debut = $date_debut;
}
/**
 * @param \DateTime $date_fin
 */
public function setDateFin($date_fin)
{
    $this->date_fin = $date_fin;
}

 /**
 * Set medecin
 *
 * @param \Doctix\MedecinBundle\Entity\Medecin $medecin
 * @return Schedule
 */
public function setMedecin(\Doctix\MedecinBundle\Entity\Medecin $medecin)
{
    $this->medecin = $medecin;

    return $this;
}

/**
 * Get medecin
 *
 * @return \Doctix\MedecinBundle\Entity\Medecin 
 */
public function getMedecin()
{
    return $this->medecin;
}

这是我的页面的呈现: rendering of my page and following the page 谢谢,如果您需要其他文件,请告诉我

这是我的js文件:

$(function () {
    $('#calendar-holder').fullCalendar({
        events: '/schedule',
        locale: 'fr',
        header: {
            left: 'prev, next, today',
            center: 'title',
            right: 'month, agendaWeek, agendaDay'
        },
     /*   buttonText: {
                        today: 'aujourd''hui',
                        month: 'mois',
                        week:  'semaine',
                        day:   'jour',
                        list:  'liste'
        } */
        //weekends: false,
        timezone: ('Africa/Bamako'),
        businessHours: {
            start: '09:00',
            end: '18:00',
            dow: [1, 2, 3, 4, 5]
        },
        allDaySlot: true,
        defaultView: 'month',
        lazyFetching: true,
        firstDay: 1,
        selectable: true,
        /*timeFormat: {
            agenda: 'h:mmt',
            '': 'h:mmt'
        },*/
        /*columnFormat:{
            month: 'ddd',
            week: 'ddd D/M',
            day: 'dddd'
        },*/
        editable: true,
        eventDurationEditable: true,
     /*   eventRender: function (event, element) {
            element.attr('href', 'javascript:void(0);');
            element.click(function(){
                $("#calendar_modal").html(moment(event.title));
                $("#calendar_modal").html(moment(event.date_debut).format("Y-m-d\TH:i:sP"));
                $("#calendar_modal").html(moment(event.date_fin).format("Y-m-d\TH:i:sP"));
                $("eventLink").attr('href', event.url);
                $("eventContent").dialog({ modal: true, title: event.title, width:350});
            });

        } */
    });
});
 

您可能会问我为什么不调用url:fc-load-events,因为这个总是在空白页上显示两个[]标签。

2 个答案:

答案 0 :(得分:0)

我遇到了类似的问题,您可以使用此捆绑包:

https://github.com/tattali/CalendarBundle

答案 1 :(得分:0)

如果完成了CRUD,请使用此EventListener并通过您的实体名称修改所有“预订”或“预订”。

<?php

namespace App\EventListener;

use App\Entity\Booking;
use Doctrine\ORM\EntityManager;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Toiba\FullCalendarBundle\Entity\Event;
use Toiba\FullCalendarBundle\Event\CalendarEvent;

class FullCalendarListener
{
    /**
     * @var EntityManager
     */
    private $em;

    /**
     * @var UrlGeneratorInterface
     */
    private $router;

    public function __construct(EntityManager $em, UrlGeneratorInterface $router)
    {
        $this->em = $em;
        $this->router = $router;
    }

    /**
     * @param CalendarEvent $calendar
     */
    public function loadEvents(CalendarEvent $calendar)
    {
        $startDate = $calendar->getStart();
        $endDate = $calendar->getEnd();
        $filters = $calendar->getFilters();

        // You may want do a custom query to populate the calendar
        // b.beginAt is the start date in the booking entity
        $bookings = $this->em->getRepository(Booking::class)
            ->createQueryBuilder('b')
            ->andWhere('b.beginAt BETWEEN :startDate and :endDate')
            ->setParameter('startDate', $startDate->format('Y-m-d H:i:s'))
            ->setParameter('endDate', $endDate->format('Y-m-d H:i:s'))
            ->getQuery()->getResult();

        foreach($bookings as $booking) {

            // create an event with the booking data
            $bookingEvent = new Event(
                $booking->getTitle(),
                $booking->getBeginAt(),
                $booking->getEndAt() // If end date is null or not defined, it create an all day event
            );

            $bookingEvent->setUrl(
                $this->router->generate('booking_show', array(
                    'id' => $booking->getId(),
                ))
            );

            /*
             * For more information see : Toiba\FullCalendarBundle\Entity\Event
             * and : https://fullcalendar.io/docs/event-object
             */
            // $bookingEvent->setBackgroundColor($booking['bgColor']);
            // $bookingEvent->setCustomField('borderColor', $booking['bgColor']);

            // finally, add the booking to the CalendarEvent for displaying on the calendar
            $calendar->addEvent($bookingEvent);
        }
    }
}