I'm working on tutorial Working with RESTful Services in CodeIgniter and i have problem with one line of code.
In user_get()
function condition if(!$this->get('id'))
throws 400 response if i try to get resource http://localhostApp/api/user/1
What am I missing out?
Do i request resources wrong way?
This is my Api controller:
class Api extends REST_Controller
{
function user_get(){
if(!$this->get('id')){ //Problem line
$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);
}
}
}
?>
If you need any additional info, please let me know.
Thank you in advance