biagidp
biagidp

Reputation: 2185

fullcalendar events from REST-ful php server

I've written a very simple RESTful php server (my first experiment with REST, so feel free to make suggestions) to respond to the fullcalendar events callback. It produces exactly the same string output as the json-events.php file in the fullcalendar json example, but for some reason fullcalendar will not accept my server's output.

I've tried messing with the headers because they're different from the ones produced by json-events.php, but I'm not really sure what's awry there, if anything.

The code for the server is below:

<?php

class Listener{
    function __construct() {
        $this->getResource();
        $this->buildResponse();
    }

    function getResource(){
        $parts = explode('/', $_SERVER["REQUEST_URI"]);
        $script_name = end(explode('/', $_SERVER["SCRIPT_NAME"]));

        $this->resource = $parts[array_search($script_name, $parts) + 1];
        $this->resource_id = $parts[array_search($script_name, $parts) + 2];
    }

    function buildResponse(){
        $method = strtolower($_SERVER["REQUEST_METHOD"]);
        $this->response_string = $method . ucwords($this->resource);
    }
    function getResponse(){
        return $this->response_string;
    }
}

$listener = new Listener();
$thing = $listener->getResponse();

$thing();

function getEvents(){
    $year = date('Y');
    $month = date('m');

    echo json_encode(array(

        array(
            'id' => 111,
            'title' => "Event1",
            'start' => "$year-$month-10",
            'url' => "http://yahoo.com/"
        ),

        array(
            'id' => 222,
            'title' => "Event2",
            'start' => "$year-$month-20",
            'end' => "$year-$month-22",
            'url' => "http://yahoo.com/"
        )
    ));
}
?>

Any input, help or suggestions would be greatly appreciated!

Thanks, David

Upvotes: 0

Views: 1239

Answers (2)

biagidp
biagidp

Reputation: 2185

Figured it out. My PHP wasn't handling extra parameters sent after the "?" in the url, so it was looking for actions that didn't exist! Oops!

Upvotes: 0

Jerod Venema
Jerod Venema

Reputation: 44632

As you guessed, it's probably your headers. I'm not sure what "fullcalendar" is, but if it's looking for a JSON response, you probably need to set your content type to application/json.

Upvotes: 1

Related Questions