function PUT() { $requiredAttributes = array('username', 'firstName', 'lastName'); $passedAttributes = $this->get_put_vars(); //print_r( $passedAttributes ); //If there is more than one item in the array if ($passedAttributes > 0) { //Seach for the required attributes in the POST array /* foreach( $requiredAttributes as $key ){ print 'key:'.$key . "\r\n"; if( !array_key_exists($key, $passedAttributes ) ){ print $key . "\r\n"; //return FRHTTPError::err400(null,'Not all required attributes supplied'); } } */ if ($this->models['User']->save($passedAttributes) != null) { $xml = new XMLAuthor(); $xml->push('User'); $xml->element(''); $xml->pop(); return $xml->getXML(); } else { return 'error'; } } else { return FRHTTPError::err400(null, 'No Attributes supplied'); } }
function errorResponse($errCode = null, $errDescription = null) { $xml = new XMLAuthor(); $xml->push('error'); if (isset($errCode)) { $xml->element('code', $errCode); } if (isset($errDescription)) { $xml->element('description', $errDescription); } $xml->pop(); return $xml->getXML(); }
function POST() { /* $requiredAttributes = array( 'id' ); */ if (array_key_exists('id', $_POST)) { //Set the id to make the model update rather than insert $this->models['Location']->ID = $_POST['id']; $this->models['Location']->save($_POST); $xml = new XMLAuthor(); $xml->push('location'); foreach ($_POST as $k => $v) { $xml->element($k, $v); } $xml->pop(); return $xml->getXML(); } else { return FRHTTPError::err400(null, 'Invalid Arguments'); } }
function GET() { //$this->returnXML = false; //$this->models['Article']->debug = true; $xml = new XMLAuthor(); if (array_key_exists('id', $_GET)) { $id = $_GET['id']; $result = $this->models['Article']->findAll(array('conditions' => "location_id = {$id}")); } else { $result = $this->models['Article']->findAll(); } $xml->push('articles'); foreach ($result as $row) { $xml->push('article'); $xml->element('id', $row['id']); $xml->element('location_id', $row['location_id']); $xml->element('title', $row['title']); $xml->element('body', $row['body']); $xml->pop(); } $xml->pop(); return $xml->getXML(); }