Class' Restserver \ Libraries \ REST_Controller' - codeigniter

时间:2018-03-24 17:36:33

标签: php codeigniter codeigniter-3

我想使用Rest api,我使用chriskacerguis/codeigniter-restserver

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

我收到了这个错误:

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

我的班级:

<?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

2 个答案:

答案 0 :(得分:0)

如果在配置文件中设置了错误的默认前缀,则会发生此错误。打开application/config/config.php并更改第

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

如果这不起作用,请告诉我,我会尝试更新我的答案并帮助您。

答案 1 :(得分:0)

在宣布你的课程之前,试试这个:

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