Skip to content

Instantly share code, notes, and snippets.

@jchamb
Created September 1, 2017 16:46
Show Gist options
  • Save jchamb/d07a5dcd74d251b6d3ecf9379e4d29a8 to your computer and use it in GitHub Desktop.
Save jchamb/d07a5dcd74d251b6d3ecf9379e4d29a8 to your computer and use it in GitHub Desktop.
ZF2 convert all request data to an array from a controller
function getRequestData()
{
if( empty($this->request) )
$this->request = $this->getRequest();
$post = $this->request->getPost()->toArray();
$get = $this->request->getQuery()->toArray();
$headers = $this->request->getHeaders()->toArray();
$body = $this->request->getContent() !== ''
? json_decode($this->request->getContent(), true)
: [];
return array_merge($headers, $get, $post, $body);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment