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
1

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I saw this answer before but it doesn't work and I got the same error.
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(){
        ...
        }
    }

1 Comment

I'm using composer and I think it doesn't need to use require or include.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.