-
-
Save i-amolo/8cdcda0d6cf2dea1c5fdb27d73421c20 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