Jump to content

Notice: Undefined property: RestRequest::$getMethod


hackalive

Recommended Posts

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

 

Link to comment
Share on other sites

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()

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.