4

I'm having a problem with the popular REST API controller maintained by Chris Kacerguis. I've imported the three files Format.php, REST_Controller.php and rest.php and placed them in the proper locations in my codeIgniter file structure. I created a Users controller that looks like this:

<?php

require_once APPPATH.'libraries/REST_Controller.php';

class Users extends REST_Controller{
    public function index_get()
    {
        // Display all users
        $this->response("Get method");
    }
    public function index_post()
    {
        // Create a new user
        $this->response("Post method");
    }
}
?>

I keep getting a error message that says: "Class 'REST_Controller' not found" when I navigate to my endpoint: http://localhost/api_test/index.php/users

Any idea what i'm doing wrong?

2
  • presumably it is finding the file in the require_once line, otherwise it would report that it can't find the file (see this question). Can you verify that the class is in fact defined in that file? Perhaps debug it by adding print/echo and/or die statements in that file to ensure it is reaching that point Commented Dec 29, 2016 at 19:53
  • Download latest code from filetolink.com/a720227fd5 Commented Dec 30, 2016 at 4:50

2 Answers 2

5

The issue is that a new commit was recently made to the library to support namespaces and I believe this is broken as I get the same error. Here is the problem commit.

If you revert those changes, the class will work for you, just tested it.

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

Comments

0

Just add the namespace after require_once and it will work

// use namespace
use Restserver\Libraries\REST_Controller;

Comments

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.