【问题标题】:codeigniter rest server issuecodeigniter 休息服务器问题
【发布时间】:2012-12-28 12:38:43
【问题描述】:

我正在使用 phil sturgeon 的 codeigniter rest server。我正在关注 net.tutsplus 的 restfull 服务教程 here 。我已经在本地安装了其余的服务器,并在将其安装到服务器上之前先看看它是如何工作的。

我从一开始就有很多问题。 我在我的主控制器中包含了 REST_Controller.php 文件,当我这样做时,在该行之后:

 class Courses extends REST_Controller {

  function index (){
  $this->load->view('index');
  }

}

它给出错误说: 致命错误:找不到类“REST_Controller”。 但是如果我用 CI_Controller 替换 REST_Controller 它会加载索引视图。 我被困在这个问题上 4 个小时,没有任何事情能按我的方式工作。 需要你的建议 提前谢谢

【问题讨论】:

    标签: codeigniter-2


    【解决方案1】:

    来自文档:https://github.com/philsturgeon/codeigniter-restserver#installation

    快速的方法是在class Courses extends REST_Controller {之前添加

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

    另外,考虑使用__autoload Using the PHP spl_autoload_register() with Codeigniter

    HTH

    【讨论】:

    • 函数名也变成了index_get()。如果你的方法是 post,那么函数应该以 _post 结尾。
    【解决方案2】:

    应该是这样的

    class Courses extends REST_Controller {
    
     function index_get (){
       $this->response(array('success' => 'Yes it is working'), 200);
     }
    
    }
    

    【讨论】:

      【解决方案3】:

      在 config.php 文件的顶部添加这个函数。这样您就不需要将任何文件包含到任何扩展 REST_Controller 的控制器中。

      function __autoload($classname) {
          if (strpos($classname, 'CI_') !== 0) {
              $file = APPPATH . 'libraries/' . $classname . '.php';
              if (file_exists($file) && is_file($file)) {
                  @include_once($file);
              }
          }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-12-19
        • 1970-01-01
        • 2013-05-28
        • 1970-01-01
        • 2011-03-24
        • 1970-01-01
        相关资源
        最近更新 更多