hackalive Posted June 17, 2012 Share Posted June 17, 2012 Hi guys, When using http://www.gen-x-design.com/archives/create-a-rest-api-with-php/ And implementing this part: $data = RestUtils::processRequest(); switch($data->getMethod) { // this is a request for all users, not one in particular case 'get': $user_list = getUserList(); // assume this returns an array if($data->getHttpAccept == 'json') { RestUtils::sendResponse(200, json_encode($user_list), 'application/json'); } else if ($data->getHttpAccept == 'xml') { // using the XML_SERIALIZER Pear Package $options = array ( 'indent' => ' ', 'addDecl' => false, 'rootName' => $fc->getAction(), XML_SERIALIZER_OPTION_RETURN_RESULT => true ); $serializer = new XML_Serializer($options); RestUtils::sendResponse(200, $serializer->serialize($user_list), 'application/xml'); } break; // new user create case 'post': $user = new User(); $user->setFirstName($data->getData()->first_name); // just for example, this should be done cleaner // and so on... $user->save(); // just send the new ID as the body RestUtils::sendResponse(201, $user->getId()); break; } I get an error; Notice: Undefined property: RestRequest::$getMethod Any ideas why or how I can fix it? Cheers in advance Quote Link to comment Share on other sites More sharing options...
boompa Posted June 17, 2012 Share Posted June 17, 2012 There's a bug in the posted code (that you're using). Perhaps you should let the author know. $data->getMethod That's looking for a property (a public member variable) called getMethod in the object to which $data is pointing. There is no such property. There *is*, however, a *method* (function) called getMethod, and to call a method on an object you need to provide parentheses, like this: $data-getMethod() Quote Link to comment Share on other sites More sharing options...
hackalive Posted June 17, 2012 Author Share Posted June 17, 2012 I assume you meant switch($data->getMethod()) As that worked Had to change all $data->XX to $data->XX() THANKS VERY MUCH! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.