samedi 23 janvier 2016

configure codeIgniter for Emberjs

i am new in codeIgniter, i want to make rest apis using codeIgniter for ember project,

i refered thislink ,but i want to use rest verbs in codeIgniter

i used get verb :

$route['api/v1/project']['get'] = 'project/projects';

and,project controller

<?php

defined('BASEPATH') OR exit('No direct script access allowed');
require APPPATH . '/libraries/REST_Controller.php';

class Example extends REST_Controller {

    function __construct()
    {
        header('Access-Control-Allow-Origin: *');
        parent::__construct();
      
    }

    public function projects_get()
    {
       $projects = [
           ['id' => 1, 'name' => 'John', 'email' => 'john@example.com', 'fact' => 'Loves coding'],
         ['id' => 2, 'name' => 'Jim', 'email' => 'jim@example.com', 'fact' => 'Developed on CodeIgniter'],
             ['id' => 3, 'name' => 'Jane', 'email' => 'jane@example.com', 'fact' => 'Lives in the USA', ['hobbies' => ['guitar', 'cycling']]],
         ];

              $this->response($projects, REST_Controller::HTTP_OK); // OK 
      }
  }

thank




Aucun commentaire:

Enregistrer un commentaire