Codeigniter用作曲家安装rest api

时间:2018-03-08 12:44:58

标签: php codeigniter composer-php codeigniter-restserver

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

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

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

是的,这是转储问题

1 个答案:

答案 0 :(得分:0)

有用的链接:codeigniter-restserver Handling Request

<?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调用,那么如果您正在对/ example进行HTTP POST调用,它会调用Api#example_get()方法,例如,它会调用Api#example_post()方法