简体   繁体   English

如何使用PHP代码将日期从数据库表加载到fullcalender? [没有ajax]

[英]How can I load dates from database table to fullcalender using PHP code? [without ajax]

I have a fullCalender plugin and a database table with a field in the DATETIME datatype. 我有一个fullCalender插件和一个数据库表,其中的DATETIME数据类型为一个字段。 Currently my calendar is just showing the events that I have hardcoded in the calendar.js file. 目前,我的日历仅显示我已在calendar.js文件中进行硬编码的事件。

title: 'event_name', 
start: new Date(y, m, 16),

Some part of my code in calendar.js looks similar to the above section. 我在calendar.js中的部分代码与上一节类似。

I have the basic knowledge in PHP and MySQL and also knowing very well that I can do it with the ajax calls. 我具有PHP和MySQL的基本知识,并且非常了解我可以使用ajax调用来做到这一点。 But I am in a requirement to do the same in PHP. 但是我需要在PHP中执行相同的操作。 Now how can I load the events[dates] from my table and show them in the curresponding dates in the calendar? 现在如何从表格中加载事件[日期]并在日历的当前日期中显示它们?

[Please notice that I am restricted to use ajax and json ] [请注意,我被限制使用ajaxjson ]

Some help from your side may take me through my solution. 您的一些帮助可能会帮助我解决问题。 Thank you. 谢谢。

maybe this is the solution: 也许这是解决方案:

  1. in a .htaccess add rewrite rule: RewriteRule ^calendardata.js$ calendardata.php [NC,L] 在.htaccess中添加重写规则:RewriteRule ^ calendardata.js $ calendardata.php [NC,L]
  2. in calendardata.php print your data as in the calendardata.js 在calendardata.php中像在calendardata.js中一样打印数据
  3. include calendardata.js in your page 在页面中包含calendardata.js

Can simply pass the events array from php to javascript variable and then pass that javascript variable to the fullcalendar plugin initialization object 可以简单地将事件数组从php传递到javascript变量,然后将该javascript变量传递给fullcalendar插件初始化对象

Somewhere in html output: html输出中的某处:

<script>
  var events = <?= json_encode( $eventsArray) ?>;
</script>

Then in calendar.js 然后在calendar.js

$(function(){
   $('#myCalendarDiv').fullcalendar({
        events: events,
        /* other options */
   });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM