Created
May 25, 2012 09:41
-
-
Save joernroeder/2786989 to your computer and use it in GitHub Desktop.
JJRestApiExtension Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class ExtensionName_RestApiExtension extends JJ_RestApiExtension { | |
public static $url_handlers = array( | |
'ExtensionName/$Action/$ID' => 'handleExtensionName' | |
); | |
public static $allowed_actions = array( | |
'handleExtensionName' | |
); | |
/** | |
* sets api access to read only | |
* | |
* @var boolean | |
*/ | |
protected $isReadOnly = true; // remove this line if your Extension uses read/write access | |
/** | |
* returns the current user | |
* | |
* @todo modify fields via url params. restrict fields to api_access[$context]. | |
* | |
* @return Data | |
*/ | |
public function handleExtensionName($request) { | |
// security checks and response headers | |
parent::handle(); | |
// use $this->convert{type} if you return raw data such as arrays | |
return $this->formatter->convertArray(array("foo" => "bar")); | |
$object = DataObject::get_by_id("Foo", 1); | |
// get options | |
$opts = $this->getOptionsFor("Foo", "view"); // api_access key (view/edit/delete etc) | |
// use $this->toApiObject($obj, $opts) if you're playing with DataObjects | |
return $this->toApiObject($object, $opts) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment