Skip to content

Instantly share code, notes, and snippets.

@Tjoosten
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tjoosten/53eaa62c8d80456e08d4 to your computer and use it in GitHub Desktop.
Save Tjoosten/53eaa62c8d80456e08d4 to your computer and use it in GitHub Desktop.
<?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