提问者:小点点

在Codeigniter和REST API服务中找不到类“REST\U控制器”


我对Chris Kacerguis维护的流行REST API控制器有问题。我已经导入了三个文件Format.php,REST_Controller.php和rest.php,并将它们放在我的codeIgniter文件结构中的适当位置。我创建了一个用户控制器,看起来像这样:

<?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");
    }
}
?>

当我导航到我的终结点时,我一直收到一条错误消息,上面写着:"类'REST_Controller'未找到":http://localhost/api_test/index.php/users

知道我做错了什么吗?


共2个答案

匿名用户

问题是最近对库进行了一次新的提交以支持名称空间,我相信这一点已被打破,因为我遇到了相同的错误。这就是问题所在。

如果您恢复这些更改,该类将为您工作,只需对其进行测试。

匿名用户

只需在require_之后添加名称空间一次,它就可以工作了

// use namespace
use Restserver\Libraries\REST_Controller;