0

I'm trying to fire off a request to my controller via a DOJO request,

        request("/category/", {
            method: "PUT",
              data: {
                    original: event.target.getAttribute("data-original"),
                    edited: event.target.getAttribute("data-edited"),
                    id: event.target.getAttribute("data-id")
                }
        }).then(function(response) {
            response = JSON.parse(response);
            if(response.success) {
                createRow(response.id);
            } else {
                // handle validation errors here
            }
        });

Which fires a PUT request to my /category/ route, which is picked up and sent to the controller, at this point I'd like to access the $_PUT superglobal which I believe doesn't exist the same way you would access the $_POST superglobal.

public function putIndex()
{
    try {
        try {
            $this->category->edit(
                new CategoryVO($request['id'], $request['original']),
                new CategoryVO($request['id'], $request['edited'])
            ); // This is where I'd like to access the values sent in the PUT request
            echo json_encode(
                array(
                    "success" => true
                )
            );
        } catch (CategoryValidation $validationException) {
            echo json_encode(
                array(
                    "success" => false,
                    "validation_errors" => $this->service->prepareErrors(
                        $validationException
                    )
                )
            );
        }
    } catch(\Exception $e) {
        echo json_encode(
            array(
                "success" => false,
                "unexpected_exception" => true
            )
        );
    }
}

FYI: Custom built framework so don't have any of those nice features that zf2/codeigniter may come with.

Jack hardcastle
  • 2,748
  • 4
  • 22
  • 40

2 Answers2

0

See if this helps you: https://stackoverflow.com/a/6270140/6097905

Basically you need to get the request method ( I suppose it could come in handy anyway ), and then retrieve the data, and store it in a static way.

Community
  • 1
  • 1
VirginieLGB
  • 548
  • 2
  • 15
0

You're correct that there isn't a $_PUT superglobal, and data sent in a PUT request isn't going to appear in $_POST.

You have to manually read the data from php://input and then store it somewhere.

Googling "PHP PUT data" yields this top result, which has a pretty good example: http://www.lornajane.net/posts/2008/accessing-incoming-put-data-from-php

VoteyDisciple
  • 37,319
  • 5
  • 97
  • 97