Last active
August 29, 2015 14:11
-
-
Save Tjoosten/53eaa62c8d80456e08d4 to your computer and use it in GitHub Desktop.
This file contains 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
<?php | |
defined('BASEPATH') OR exit('No direct script access allowed'); | |
require(APPPATH.'/libraries/REST_Controller.php'); | |
class Welcome extends CI_Controller { | |
function user_get() | |
{ | |
if(!$this->get('id')) | |
{ | |
$this->response(NULL, 400); | |
} | |
$user = $this->user_model->get( $this->get('id') ); | |
if($user) | |
{ | |
$this->response($user, 200); // 200 being the HTTP response code | |
} | |
else | |
{ | |
$this->response(NULL, 404); | |
} | |
} | |
function user_post() | |
{ | |
$result = $this->user_model->update( $this->post('id'), array( | |
'name' => $this->post('name'), | |
'email' => $this->post('email') | |
)); | |
if($result === FALSE) | |
{ | |
$this->response(array('status' => 'failed')); | |
} | |
else | |
{ | |
$this->response(array('status' => 'success')); | |
} | |
} | |
function users_get() | |
{ | |
$users = $this->user_model->get_all(); | |
if($users) | |
{ | |
$this->response($users, 200); | |
} | |
else | |
{ | |
$this->response(NULL, 404); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment