我是zend的新手,我使用完整的日历来创建活动,我的活动存储在数据库中,但没有在日历上显示我如何在日历上显示事件? 这是我的代码:
<?php
// module/Album/view/album/album/add.phtml:
$title = 'Create New Event';
$this->headTitle($title);
?>
<h3><?php echo $this->escapeHtml($title); ?></h3>
<?php
$form = $this->form;
$form->setAttribute('action', $this->url('event', array(
'action' => 'create',
'id' => $form->get('calendar_id')->getValue()
)));
$form->prepare();
echo $this->form()->openTag($form);
echo $this->formHidden($form->get('event_id'));
echo $this->formHidden($form->get('calendar_id'));
echo $this->formHidden($form->get('author_id'));
echo $this->formRow($form->get('title'));
echo $this->formRow($form->get('description'));
echo $this->formRow($form->get('begin'));
echo $this->formRow($form->get('end'));
echo $this->formSubmit($form->get('submit'));
echo $this->form()->closeTag();
?>
<?php $this->headScript()->captureStart(); ?>
$(function(){
$('*[name=begin]').appendDtpicker({
"dateFormat": "YYYY-MM-DD hh:mm:00"
} );
$('*[name=end]').appendDtpicker({
"dateFormat": "YYYY-MM-DD hh:mm:00"
});
});
<?php $this->headScript()->captureEnd();
这是我的活动节目代码:
<?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>Author Calender:
<?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>
<?php $this->headScript()->captureStart(); ?>
$(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.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;
},
});
});
<?php $this->headScript()->captureEnd();
这是我的事件加载动作:
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');
}
}
这是我的回复:
[{"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"}]
我如何在日历上显示事件?
答案 0 :(得分:0)
问题在于您尝试传递给新Date函数的日期格式。
您不能使用以下代码创建js Date对象:new Date('2014-03-02 20:00:00')
。如果在浏览器的控制台中运行它,则会失败。您必须先将其转换为包含时区数据的“真实”日期时间。
所以你要做的就是以某种方式分离你拥有的日期字符串的值
eventData.start = new Date(year, month, day, hours, minutes, seconds, milliseconds);
同样的事情
eventData.end