如何在 ZF2 中显示全日历上的 JSON 事件数据


how to show json event data on fullcalender in zf2?

我是 zf2 的新手,我使用全日历来显示日历事件,为此我做了一个加载操作,它返回我的响应如下:

[{"event_id":"2","calendar_id":"1","author_id":"1","title":"Launch","description":"Launch Break","begin":"2014-03-02 20:00:00","end":"2014-03-31 16:53:00","calendar_title":"Hijri Calender","author_email":"arif.liaqat@yahoo.com"},{"event_id":"79","calendar_id":"1","author_id":"1","title":"cccvcv","description":"bcbcbbcbbcbccbcbb","begin":"2014-03-31 21:00:00","end":"2014-04-08 11:16:00","calendar_title":"Hijri Calender","author_email":"arif.liaqat@yahoo.com"},{"event_id":"80","calendar_id":"1","author_id":"1","title":"dgdgdgdgdgdg","description":"dgdgdgdgdg","begin":"2014-04-01 21:00:00","end":"2014-04-08 11:17:00","calendar_title":"Hijri Calender","author_email":"arif.liaqat@yahoo.com"}]

这是我的加载操作:

public function loadAction()
    {
        $response = $this->getResponse();
        //if ($request->isPost()) {
            $id = (int) $this->params()->fromRoute('id', 0);
            if ($id) {
                $events = $this->getEventTable()->fetchAllByCalendar($id);
                $response->setContent('Zend'Json'Json::encode($events));
            }
        //}
        return $response;
    }

这是我的日历显示代码:

 public function showAction()
    {
        if ($this->zfcUserAuthentication()->hasIdentity())
        {
            $id = (int) $this->params()->fromRoute('id', 0);
            if (!$id) {
                return $this->redirect()->toRoute('calendar', array(
                    'action' => 'create'
                ));
            }
            $calendar = $this->getCalendarTable()->getCalendar($id);
            return array('calendar' => $calendar);
        }
        else
        {
            $this->redirect()->toRoute('zfcuser/login');
        }
    }

这是我的show.phtml,其中我在日历上显示事件:

 <?php
$calendar = $this->calendar;
$title = $this->escapeHtml($calendar->title);
$this->headTitle($title);
 ?>
 <h3><?php echo $this->escapeHtml($title); ?></h3>
 <p>Click in the blank space to add a new term, click on your choice to see the detail of y.</p>
 <p>Calender Author:
<?php echo $this->escapeHtml($calendar->email) . ' ' . $this->gravatar($this->escapeHtml($calendar->email)); ?>
 </p>
 <p>description: <?php echo $this->escapeHtml($calendar->description); ?></p>
 <p><a href="<?php echo $this->url('calendar');?>">Back to list Calender</a></p>
  <div id="fullcalendar"></div>
  <script>
  $(document).ready(function() {
// page is now ready, initialize the calendar...
$('#fullcalendar').fullCalendar({

    header: {
        left: 'prev,next today',
        center: 'title',
        right: 'month,agendaWeek,agendaDay'
    },
    defaultView: 'month',
    allDaySlot: false,
    events: '<?php echo $this->url('event',array('action'=>'load', 'id' => $this->escapeHtml($calendar->calendar_id)));?>',
    eventDataTransform: function(eventData) {
        //eventData.start = new Date(eventData.begin);
        //eventData.end = new Date(eventData.end);
        eventData.start = new Date(eventData.year, eventData.month, eventData.day, eventData.hours, eventData.minutes, eventData.seconds, eventData.milliseconds);
        eventData.end = new Date(eventData.year, eventData.month, eventData.day, eventData.hours, eventData.minutes, eventData.seconds, eventData.milliseconds);
        eventData.allDay = false;
        eventData.url = '<?php echo $this->url('event',array('action'=>'show'));?>' + '/' + eventData.event_id;
        return eventData;
    },
    dayClick: function(date, allDay, jsEvent, view) {
        var action = '<?php echo $this->url('event',array('action'=>'create', 'id' => $this->escapeHtml($calendar->calendar_id))) ?>';
        var dateUri = date.getTime() / 1000;
        var allDayUri = allDay ? 1 : 0;
        console.log(action + '/' + dateUri  + '/' + allDayUri);
        window.location = action + '/' + dateUri  + '/' + allDayUri;
    },
    //console.log(events);
});
 });    
  </script>

如何使用事件的 JSON 数据在日历上显示事件?任何建议都应得到认可

我对日历没有任何经验,但我目前正在处理需要 json 的类似东西。因此,我将引导您找到我在网络上发现有用的内容,以获得我正在寻找的结果。

重要的部分。

'strategies' => array(
        'ViewJsonStrategy',
    ),

module.config 中添加上面的代码.php如果还没有的话。

然后阅读这两个简短的教程。从 ZF2 控制器操作返回 JSON ,Zend Framework 2 AJAX:从控制器操作返回 JSON 响应。正确的方式。

如果这不是你要找的,请不要评判我。我只是想帮助:p