Skip to content

Instantly share code, notes, and snippets.

@i-amolo
Forked from iscalfonsoolivares/accounts.php
Created October 3, 2020 08:54
Show Gist options
  • Select an option

  • Save i-amolo/8cdcda0d6cf2dea1c5fdb27d73421c20 to your computer and use it in GitHub Desktop.

Select an option

Save i-amolo/8cdcda0d6cf2dea1c5fdb27d73421c20 to your computer and use it in GitHub Desktop.
Getting json data from request with codeigniter
// curl -i -X POST -H 'Content-Type: application/son' -d '{"name": "New item", "year": "2009"}' http://localhost/api/accounts
$this->load->helper("security");
$stream = $this->security->xss_clean( $this->input->raw_input_stream );
$new_account = json_decode(trim($stream), true);
$accounts = array();
$accounts[] = array('foo' => 'bar');
$accounts[] = array('foo' => 'bar');
$accounts[] = array('foo' => 'bar');
$accounts[] = $new_account;
$accounts[] = array('method' => $this->input->method());
$this->output
->set_content_type('application/json')
->set_output(json_encode($accounts, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment