简体   繁体   中英

Class 'REST_Controller' not found with Codeigniter and REST API service

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?

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.

Just add the namespace after require_once and it will work

// use namespace
use Restserver\Libraries\REST_Controller;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM