21282 Posts in 5730 Topics by 2601 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 5431 Views |
-
How to import json array into jQuery calendar

12 July 2009 at 11:04pm
Hi
I'm trying to feed a jQuery calendar with data from Silverstripe. I've installed the perfectly well-working Calendar Event module, but all I want now is to pull out some Calendar Events and return them as a json array. Here is the code for initiating the calendar:
$(document).ready(function() {
$('#calendar').fullCalendar({
draggable: true,
events: "json_events.php",
eventDrop: function(event, delta) {
alert(event.title + ' was moved ' + delta + ' days\n' +
'(should probably update your database)');
},
loading: function(bool) {
if (bool) $('#loading').show();
else $('#loading').hide();
}
});
});And here is the json_events.php:
<?php
$year = date('Y');
$month = date('m');echo json_encode(array(
array(
'id' => 1,
'title' => "Event1",
'start' => "$year-$month-10",
'url' => "http://yahoo.com/"
),
array(
'id' => 2,
'title' => "Event2",
'start' => "$year-$month-20",
'end' => "$year-$month-22",
'url' => "http://yahoo.com/"
)
));?>
The question is just, how or what should I do to get this working with silverstripe. Should I use the restfull server API? And if yes, how would I do that since I can't find any documentation on how to use the restfull server with json export.
Many thanks
Joel
-
Re: How to import json array into jQuery calendar

13 July 2009 at 1:41am
Hm. Just write a method in your Controller, that returns your Data as json?
Something like:// put this in your Page_Controller or <whatever>_Controller
public function json(){
// gather event data to an array
return json_encode($arrayData);
}Then you can call the URL of that page and append /json to it.
eg. http://localhost/silverstripe/page/json (will call the json method of the page-Controller) -
Re: How to import json array into jQuery calendar

13 July 2009 at 9:35pm
But of course, yes, thanks, works like a charm.
| 5431 Views | ||
|
Page:
1
|
Go to Top |


