Created
May 12, 2016 17:02
-
-
Save iscalfonsoolivares/47b2fa0e1d271419cf6b2a129f9f7de1 to your computer and use it in GitHub Desktop.
Getting json data from request with codeigniter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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