0

I want to use Rest api,I'm using chriskacerguis/codeigniter-restserver:

"require": {
    "php": ">=5.3.7",
    "chriskacerguis/codeigniter-restserver": "^3.0"
},

I got this error:

   Fatal error: Class 'Restserver\Libraries\REST_Controller' not found 

my class:

<?php
  namespace Restserver\Libraries;
  use Restserver\Libraries\REST_Controller;

   class Api extends REST_Controller {

     public function __construct(){
         parent::__construct();
}



public function user_get()
{

    $users = [
        'id' => 100, // Automatically generated by the model
        'name' => $this->post('name'),
        'email' => $this->post('email'),
        'message' => 'Added a resource'
    ];

    $this->response($users, REST_Controller::HTTP_OK);
}

}

+controllers
   +Api
      Api.php
S.M_Emamian
  • 17,005
  • 37
  • 135
  • 254

2 Answers2

0

This error can occur if the wrong default prefix is set in the config file. Open application/config/config.php and change the line

$config['subclass_prefix'] = 'MY_'; to: $config['subclass_prefix'] = 'REST_';

Let me know if this doesn't work and I will try to update my answer and help you further.

Michael Krikorev
  • 2,126
  • 1
  • 18
  • 25
0

Before declaring your class, try this:

    <?php
    defined('BASEPATH') OR exit('No direct script access allowed');
    require APPPATH . 'path/to/REST_Controller.php';
    class Apie extends REST_Controller {
        function __construct(){
        ...
        }
    }