在CodeIgniter RESTful API中获取错误

时间:2018-06-07 09:37:40

标签: codeigniter codeigniter-restserver

defined('BASEPATH') OR exit('No direct script access allowed');

require('application/libraries/REST_Controller.php');

use Restserver\Libraries\REST_Controller;

class demo extends REST_Controller {

  function __construct(){

    parent::__construct();
  }

  public function demo1_get()
  {
    echo 'demo 1';
  }

} 

错误图片 enter image description here

这是我的REST_Controller enter image description here

嗨,我在编写Codeigniter RESTful API时出错了。请帮我解决这个问题。

2 个答案:

答案 0 :(得分:0)

应该是这样的:

确保您的图书馆文件夹中有REST_Controller.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

require_once APPPATH . '/libraries/REST_Controller.php';


class Demo  extends REST_Controller
{
    function __construct(){

      parent::__construct();
    }

   public function demo1_get()
   {
     echo 'demo 1';
   }
}

答案 1 :(得分:0)

您需要点击链接https://itsolutionstuff.com/post/codeigniter-3-restful-api-tutorialexample.html

然后运行代码后,您将得到一个小错误无法加载请求的语言文件:language / english / rest_controller_lang.php

问题是codeigniter找不到rest_controller转换。您只需要创建此文件/application/languages/english/rest_controller_lang.php

然后将此代码复制并粘贴到内部:

public Flux<UserDto> fetchUserEvent() {
        return Flux.interval(Duration.ofSeconds(20)).map(intr -> generateUserEvent()).flatMapIterable(x -> x);
    }

generateUserEvent() - verify if new user added in DB. If it found user data, will return the same or will return empty object (new UserDto())

希望这会有所帮助

相关问题