1

我用这个安装codeigniter: https ://github.com/kenjis/codeigniter-composer-installer

当我尝试安装 REST API 时: https ://github.com/chriskacerguis/codeigniter-restserver

当我扩展 REST_Controller 时工作正常,但是当我用 Composer 安装他时如何运行 REST API 示例?

是的,这是转储问题

4

1 回答 1

1

有用的链接:codeigniter-restserver处理请求

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

class Api extends REST_Controller
{
  public function example_get()
  {
    echo "Called is called by Get method";
  }

  public function example_post()
  {
   echo "Called is called by Post method"; 
  }
}

?>

所以你只需要调用 localhost/public/api/example 这将调用 Api::example_get()

当您的控制器从 REST_Controller 扩展时,方法名称将附加用于访问请求的 HTTP 方法。例如,如果您对 /example 进行 HTTP GET 调用,它将调用 Api#example_get() 方法,否则,如果您对 /example 进行 HTTP POST 调用,它将调用 Api#example_post () 方法

于 2018-03-08T13:41:29.113 回答