John Tatu
John Tatu

Reputation: 525

Getting 404 error in codeigniter bonfire using restful api

I am having trouble in setting Rest Server for my CI bonfire.

I have installed it following this instructions here : https://github.com/philsturgeon/codeigniter-restserver.

I have created a new controller that looks like this:

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

require(APPPATH.'libraries/REST_Controller.php');

class Hello extends REST_Controller{

function user_get()  
{  
    $data = array('returned: '. $this->get('id'));  
    $this->response($data);  
}  

function user_post()  
{         
    $data = array('returned: '. $this->post('id'));  
    $this->response($data);  
}  

function user_put()  
{         
    $data = array('returned: '. $this->put('id'));  
    $this->response($data);  
}  

function user_delete()  
{  
    $data = array('returned: '. $this->delete('id'));  
    $this->response($data);  
}  

}

?>

Now, my url looks like this : http://website.com/public/admin/hello/user/id/1 Here I am getting a 404 error page.

What am I missing ? Did I request the controller badly or is there a routes issue ? Any help will be appreciated.

Upvotes: 0

Views: 2241

Answers (1)

John Tatu
John Tatu

Reputation: 525

Okay, it seems that my issue was regarding the codeigniter routes. Commenting those line solves my issue:

$route[SITE_AREA .'/([a-z_]+)/(:any)/(:any)/(:any)/(:any)/(:any)']      =    "$2/$1/$3/$4/$5/$6";
$route[SITE_AREA .'/([a-z_]+)/(:any)/(:any)/(:any)/(:any)']     = "$2/$1/$3/$4/$5";
$route[SITE_AREA .'/([a-z_]+)/(:any)/(:any)/(:any)']        = "$2/$1/$3/$4";
$route[SITE_AREA .'/([a-z_]+)/(:any)/(:any)']       = "$2/$1/$3";
$route[SITE_AREA .'/([a-z_]+)/(:any)']              = "$2/$1/index";

But even better writing a new route above those ones is doing the job.

$route[SITE_AREA .'/hello/(:any)']  = "admin/hello/$1";

Hope someone will find this handy.

Upvotes: 1

Related Questions