php - REST 服务不工作-Code Igniter

标签 php codeigniter rest

我想在我的项目中实现 Phill Sturgeon CodeIgniter RESTServer 库。
我分别将文件rest.php、Format.php、REST_Controler.php复制到文件夹config、library、library中。

我使用以下代码创建了名为 services 的 Controller :

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

class services extends REST_Controller {  

    function Teams_get(){

        $teamNames=$this->team_model->getTeamNames();

         $this->response($teamNames);
    }

TeamModel 在我的 autoload.php 中自动加载。当我想在浏览器中运行 Teams_get 方法时,结果是:

{"status":false,"error":"未知方法。"}

我读到here我应该更改 REST_Controler.php 配置文件,但只有在 POST 方法不起作用时才应进行此更改。

我的服务应该是公开的,所以我不需要身份验证方法。

这里出了什么问题?

最佳答案

调用 API 时,URL 应该只是方法的名称,不带 _get(或 _post)。这是由 REST 服务器根据 URL 的调用方式添加的(GETPOST)。

因此,要调用您的 Teams_get 方法,您需要将 GET 请求发送到 URL /services/Teams(而不是 >/services/Teams_get)。

文档:https://github.com/philsturgeon/codeigniter-restserver#handling-requests

关于php - REST 服务不工作-Code Igniter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15163218/

相关文章:

php - 我的sql错在哪里?

php - 使用 PHP 执行 XQuery

php - 带有链接的 codeigniter View 中的回显计数行数

javascript - 如何在Codeigniter(最新版本) View 中使用fancybox

php - parsedown设置图片宽高

iphone - 从 iOS 应用程序向 RESTful Web 服务发送数据

php - 我应该选择这两个数据库设置中的哪一个?

php - 这个 mysql_result 语句的 mysqli 等效项是什么?

java - neo4j-rest-graphdb 无法处理与 Neo4J 2.0.x 的交易

android - 存储 HTTP/REST 请求以防连接不可用