Fetch by id
When trying to fetch an Object (using Backbone) this call http://xxxxxxx.com/api/usuarios/439 produces {"status":false,"error":"Unknown method."}
Is it possible the server does not supports GET with ID?
Hello, the library supports that easily. Could you please post your controller and routes?
Oh, i see. I need to define a route like this $route['api/usuarios/(:any)'] = 'api/usuarios/index_get/$1 to make it work right? Sorry, i thought the library was doing it on background. Thanks! =)
Just tried, but didn't work: // Routes $route['api/usuarios/(:any)'] = 'api/usuarios/index_get/$1';
// Controller /application/controllers/api/usuarios.php class Usuarios extends REST_Controller { public function index_get($id) { [....] } }
// Browser URL: http://local.xxxxx.com/api/usuarios/439 // Response: {"status":false,"error":"Unknown method."}
Your route would be something like this:
$route['api/usuarios/(:any)'] = 'api/usuarios/$1';
Since I can't see your whole controller, I can't totally speak to your code.
I made it simpler, here is my controller:
// Controller: /application/controllers/api/usuarios.php require_once APPPATH . 'libraries/REST_Controller.php'; class Usuarios extends REST_Controller { public function index_get($id = null) { var_dump($id);exit; } }
// Routes $route['usuarios/(:any)'] = 'usuarios/$1';
// URL http://local.xxxxx.com/usuarios/439
// Browser Output {"status":false,"error":"Unknown method."}
Just updated the library thinking the code was outdated, but keeps doing the same thing =( Any Idea?
I solved it. The route was wrong, it should be: $route['usuarios/(:any)'] = 'usuarios/index/$1'; Because index is the "resource". Thanks @chriskacerguis ! =)