我的Codeigniter代码中找不到类“ REST_Controller”,如何解决。

时间:2019-01-10 08:08:25

标签: rest codeigniter-3

我是REST API的新手。我想使用codeigniter创建REST API。但是我遇到的错误是我无法解决自己的问题。

控制器:-

defined('BASEPATH')或exit('不允许直接脚本访问');

require(APPPATH。'/ libraries / REST_Controller.php'); 需要APPPATH。 '/libraries/Format.php';

Api类扩展了REST_Controller {

public function __construct()
{
    parent::__construct();
    $this->load->model('book_model');

}

// API-获取所有书籍     函数books_get(){

    $result = $this->book_model->getallbooks();
    if($result){
        $this->response($result, 200); 
    } 
    else{
        $this->response("No record found", 404);
    }
}

型号代码:-

类Book_model扩展了CI_Model {

  public function __construct(){
    parent::__construct();
  }


 //API call - get all books record
public function getallbooks(){   
    $this->db->select('id, name, price, author, category, language, ISBN, publish_date');
    $this->db->from('tbl_books');
    $this->db->order_by("id", "desc"); 
    $query = $this->db->get();
    if($query->num_rows() > 0){
      return $query->result_array();

    }else{
      return 0;
    }
}

我在邮递员测试中的错误:-

enter image description here

enter image description here

0 个答案:

没有答案