06-02-2015, 04:03 PM
I am trying to develop REST APIs for my website. I am using CodeIgniter's PHP Framework. I have followed the tutorial mentioned on http://code.tutsplus.com/tutorials/worki...--net-8814 to create the restful apis. The tutorial is based upon the code developed on https://github.com/chriskacerguis/codeig...restserver
I have placed the rest.php in application/config folder and REST_Controller.php in application/libraries/
I have created an api in application/controllers/example.php
require APPPATH.'/libraries/REST_Controller.php';
I have a .htaccess file as below:
However when I send a GET Request to mywebsite.com/example/user/id/1 it redirects to the homepage. Could someone guide me
I have placed the rest.php in application/config folder and REST_Controller.php in application/libraries/
I have created an api in application/controllers/example.php
require APPPATH.'/libraries/REST_Controller.php';
Code:
class example extends REST_Controller
{
function __construct()
{
// Construct our parent class
parent::__construct();
}
function user_get()
{
if(!$this->get('id'))
{
$this->response(NULL, 400);
}
// $user = $this->some_model->getSomething( $this->get('id') );
$users = array(
1 => array('id' => 1, 'name' => 'Some Guy', 'email' => '[email protected]', 'fact' => 'Loves swimming'),
2 => array('id' => 2, 'name' => 'Person Face', 'email' => '[email protected]', 'fact' => 'Has a huge face'),
3 => array('id' => 3, 'name' => 'Scotty', 'email' => '[email protected]', 'fact' => 'Is a Scott!', array('hobbies' => array('fartings', 'bikes'))),
);
$user = @$users[$this->get('id')];
if($user)
{
$this->response($user, 200); // 200 being the HTTP response code
}
else
{
$this->response(array('error' => 'User could not be found'), 404);
}
}
}
Code:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
However when I send a GET Request to mywebsite.com/example/user/id/1 it redirects to the homepage. Could someone guide me