2

I'm using backbone and CodeIgniter Rest Server, The post and get requests from backbone works fine But the put and delete requester gets 404 error with the response of {"status":false,"error":"Unknown method."}

edit: I changed the source code to see which method codeigniter is trying to run my controller url is

http://local/host/impacto/index.php/interviews/

the put request url is

http://localhost/impacto/index.php/interviews/13

and the function that codeigniter is running is 13_put instead of input_put

My controller

class Interview extends REST_Controller {

function __construct(){

    parent:: __construct();
}

public function index_get(){

    echo "get";
}

public function index_post(){

    echo "post";
}

public function index_put($id){

    echo "update: " . $id;
}

public function index_delete($id){

    echo "delete: " . $id;
}
}
Idob
  • 1,620
  • 4
  • 16
  • 27
  • possible duplicate of [Handling PUT/DELETE arguments in PHP](http://stackoverflow.com/questions/2081894/handling-put-delete-arguments-in-php) – Benjamin Gruenbaum Sep 22 '13 at 14:58
  • not the same library, i'm using https://github.com/philsturgeon/codeigniter-restserver – Idob Sep 22 '13 at 17:51
  • I've hit upon exactly the same problem; sending a PUT to "Interview/{id}" calls the method "13_put()" and not "index_put(13)" as you'd expect ... – Algy Taylor Nov 25 '13 at 11:05

1 Answers1

3

I had the same problem. Accordingly, it's not an error - https://github.com/philsturgeon/codeigniter-restserver/issues/255 - you have to either overtly specify "index" as the function ("Interview/index/{id}"), or alternatively give your method a name ("rest_put($id)", so accessed Interview/rest/{id}")

Algy Taylor
  • 814
  • 13
  • 29
  • This is important as the controller has to know which method to call - it's receiving the parameter where it expects the method name. You could always try to use [`_remap`](http://ellislab.com/codeigniter/user-guide/general/controllers.html#remapping) and route to the method you expect based on custom logic. – swatkins Nov 25 '13 at 19:26