php - Codeigniter RESTful API 服务器 - XML 错误?

标签 php xml web-services codeigniter rest

我已阅读以下主题/教程:

  1. Codeigniter RESTful API Server
  2. http://code.tutsplus.com/tutorials/working-with-restful-services-in-codeigniter--net-8814
  3. https://github.com/chriskacerguis/codeigniter-restserver

而且我仍然不明白为什么我会遇到路由问题和 XML 问题。 我的网络服务 Controller 位于文件夹 controllers/api/webservice.php

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

require APPPATH.'/libraries/RESTful/REST_Controller.php';

class webservice extends REST_Controller{

     function get() {
        $data = array();
        $data['name'] = "TESTNAME";
        $this->response($data); 
     }
}

在教程中不需要添加路由,为了接收 XML 页面错误,我需要添加以下路由,否则它不会工作:

$route['api/webservice/get'] = 'api/webservice/get';

我的codeIgniter结构文件夹:

 > application
   > config
       rest.php (did not change anything from the GitHub download)
   > controllers
      > api
         webservice.php
         key.php
   > libraries
      > RESTful
         REST_Controller.php (changed line 206 to: $this->load->library('RESTful/format');)
         format.php

在教程中,以下链接在没有路由的情况下有效:

http://localhost/testRestful/index.php/api/example/users

我的只适用于路线

http://localhost/myproject/index.php/api/webservice/get

我收到以下错误: enter image description here 它没有说别的。我无法弄清楚错误所指的是哪个文件。

最佳答案

如果使用 REST_Controller,则不能编写 get 函数。 给该函数名称 test_get

class webservice extends REST_Controller{
 function test_get() {
    $data = array();
    $data['name'] = "TESTNAME";
    $this->response($data); 
 }
}

现在您可以通过此链接访问该页面

http://localhost/myproject/index.php/api/webservice/test

_get 和 _post 添加在函数的末尾以检测它是获取请求还是发布请求。

关于php - Codeigniter RESTful API 服务器 - XML 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27316055/

相关文章:

java - AXiS2 - 返回字符串值时出现问题。 < 和 > 正在转换为 < 和 >

web-services - maven-jaxb2-plugin - 忽略 ssl 错误

php - 统计对每个版本的评论?

php - 大苏尔并安装 msodbcsql17

php - Symfony2 和 Twig 中的多语言

java - 如何在android中创建自定义开关控件

php - 无法保存转录到Mysql

java - 序列化多层 XML 元素

ios - NSXMLParser 的奇怪行为与\n

java - JAX-WS 发出 GET,然后发出 GET 和 POST