Overview

Packages

  • CodeIgniter
    • Libraries
  • None

Classes

  • Format

Functions

  • _perform_ldap_auth
  • Overview
  • Package
  • Function
  • Tree
  • Todo
  1: <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2: 
  3: /**
  4:  * Example
  5:  *
  6:  * This is an example of a few basic user interaction methods you could use
  7:  * all done with a hardcoded array.
  8:  *
  9:  * @package     CodeIgniter
 10:  * @subpackage  Rest Server
 11:  * @category    Controller
 12:  * @author      Phil Sturgeon
 13:  * @link        http://philsturgeon.co.uk/code/
 14: */
 15: 
 16: // This can be removed if you use __autoload() in config.php OR use Modular Extensions
 17: require APPPATH.'/libraries/REST_Controller.php';
 18: 
 19: class Example extends REST_Controller
 20: {
 21:     function __construct()
 22:     {
 23:         // Construct our parent class
 24:         parent::__construct();
 25:         
 26:         // Configure limits on our controller methods. Ensure
 27:         // you have created the 'limits' table and enabled 'limits'
 28:         // within application/config/rest.php
 29:         $this->methods['user_get']['limit'] = 500; //500 requests per hour per user/key
 30:         $this->methods['user_post']['limit'] = 100; //100 requests per hour per user/key
 31:         $this->methods['user_delete']['limit'] = 50; //50 requests per hour per user/key
 32:     }
 33:     
 34:     function user_get()
 35:     {
 36:         if(!$this->get('id'))
 37:         {
 38:             $this->response(NULL, 400);
 39:         }
 40: 
 41:         // $user = $this->some_model->getSomething( $this->get('id') );
 42:         $users = array(
 43:             1 => array('id' => 1, 'name' => 'Some Guy', 'email' => 'example1@example.com', 'fact' => 'Loves swimming'),
 44:             2 => array('id' => 2, 'name' => 'Person Face', 'email' => 'example2@example.com', 'fact' => 'Has a huge face'),
 45:             3 => array('id' => 3, 'name' => 'Scotty', 'email' => 'example3@example.com', 'fact' => 'Is a Scott!', array('hobbies' => array('fartings', 'bikes'))),
 46:         );
 47:         
 48:         $user = @$users[$this->get('id')];
 49:         
 50:         if($user)
 51:         {
 52:             $this->response($user, 200); // 200 being the HTTP response code
 53:         }
 54: 
 55:         else
 56:         {
 57:             $this->response(array('error' => 'User could not be found'), 404);
 58:         }
 59:     }
 60:     
 61:     function user_post()
 62:     {
 63:         //$this->some_model->updateUser( $this->get('id') );
 64:         $message = array('id' => $this->get('id'), 'name' => $this->post('name'), 'email' => $this->post('email'), 'message' => 'ADDED!');
 65:         
 66:         $this->response($message, 200); // 200 being the HTTP response code
 67:     }
 68:     
 69:     function user_delete()
 70:     {
 71:         //$this->some_model->deletesomething( $this->get('id') );
 72:         $message = array('id' => $this->get('id'), 'message' => 'DELETED!');
 73:         
 74:         $this->response($message, 200); // 200 being the HTTP response code
 75:     }
 76:     
 77:     function users_get()
 78:     {
 79:         //$users = $this->some_model->getSomething( $this->get('limit') );
 80:         $users = array(
 81:             array('id' => 1, 'name' => 'Some Guy', 'email' => 'example1@example.com'),
 82:             array('id' => 2, 'name' => 'Person Face', 'email' => 'example2@example.com'),
 83:             3 => array('id' => 3, 'name' => 'Scotty', 'email' => 'example3@example.com', 'fact' => array('hobbies' => array('fartings', 'bikes'))),
 84:         );
 85:         
 86:         if($users)
 87:         {
 88:             $this->response($users, 200); // 200 being the HTTP response code
 89:         }
 90: 
 91:         else
 92:         {
 93:             $this->response(array('error' => 'Couldn\'t find any users!'), 404);
 94:         }
 95:     }
 96: 
 97: 
 98:     public function send_post()
 99:     {
100:         var_dump($this->request->body);
101:     }
102: 
103: 
104:     public function send_put()
105:     {
106:         var_dump($this->put('foo'));
107:     }
108: }
API documentation generated by ApiGen