我是zf2的新手,我使用fullcalender来显示日历的事件,我做了一个loadaction,回复我的反应如下:
[{"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数据在日历上显示事件? 任何建议应该Appriciated
答案 0 :(得分:1)
我对日历没有任何经验,但我目前正在处理需要json的类似事情。 所以我会引导你到我在网上找到的有用的东西,以便得到我正在寻找的结果。
重要的一部分。
'strategies' => array(
'ViewJsonStrategy',
),
如果您还没有,请在module.config.php中添加上述代码。
然后阅读这两个简短的教程。 Returning JSON from a ZF2 controller action, Zend Framework 2 AJAX: return JSON response from controller action. The proper way.
如果这不是你想要的,请不要评价我。我只是想帮忙:p