load->model('postmodel'); } function index() //get { if($this->uri->segment(3)==FALSE) { $data = $this->postmodel->get_post(); //print_r($data); $this->response($data); } else { $id=$this->uri->segment("3"); $data = $this->postmodel->get_post($id); $this->response($data); } } function create() //post { $data = array( 'artist' => $this->uri->segment(3), 'title' => $this->uri->segment(4), 'genre' => $this->uri->segment(5) ); $this->postmodel->create_post($data); $message = array('message' => 'Added!'); $this->response($message); } function edit() //put { $id = $this->uri->segment(6); $put_data = array( 'artist' => $this->uri->segment(3), 'title' => $this->uri->segment(4), 'genre' => $this->uri->segment(5) ); $this->postmodel->update_post($put_data, $id); $message = array('id' => $id, 'message' => 'Edited!'); $this->response($message); } function delete() //delete { $id = $this->uri->segment(3); $this->postmodel->delete_post($id); $message = array('message' => 'Deleted!'); $this->response($message); } function array2xml( $arr, $indent = '', $escape = true ) { $buff = ''; foreach ( $arr as $k => $v ) { //for a tag if ( !is_array( $v ) ) { $buff .= "$indent<$k>" . ($escape ? utf8_encode( htmlspecialchars($v) ) : $v ) . "\n"; } else { //for a list. if ( isset( $v[0] ) ) { foreach ( $v as $_k => $_v ) { if ( is_array( $_v ) ) { $buff .= "$indent<$k>\n" . $this->array2xml( $_v, $indent . "\t", $escape ) . "$indent\n"; } else { $buff .= "$indent<$k>" . ($escape ? utf8_encode( htmlspecialchars($_v) ) : $_v ) . "\n"; } } } else { $buff .= "$indent<$k>\n" . $this->array2xml( $v, $indent . "\t", $escape ) . "$indent\n"; } } } return $buff; } function response($d) { echo "\n\n".$this->array2xml($d).""; } } ?>