Skip to main content

Codeigniter API

--------- API CI ----------
1.Place Ci in localhost(or server).
2.Open config.php and set "$config['base_url']".
3.Create your service controller inside application/controllers/service_controller_name

4.Write(copy-> paste) controller code in service_controller as below:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Service_controller extends CI_Controller {

public function __construct($config = 'rest')
{
header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE");
parent::__construct();

}

public function index()
{
echo "Welcome To Codeigniter APIs. ";
}
}
?>
5. Copy code given below in .htaccess file

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

6. Now hit your base url with Service_controller.your services ready to work.

7. Set Session storage path at config.php in application/config directory.
//$config['sess_save_path'] = NULL;
$config['sess_save_path'] = sys_get_temp_dir();

Comments

  1. # constructor must called if index() is defined inside controller class.

    ReplyDelete
  2. #### How to Pass array of arrays from view to controller

    https://stackoverflow.com/questions/37127361/codeigniter-pass-array-of-arrays-from-view-to-controller

    ReplyDelete

Post a Comment