Codeigniter RESTful API服务器 - XML错误?

时间:2014-12-05 12:36:32

标签: 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
  4. 我仍然无法弄清楚为什么我遇到路由问题和XML问题。 我的webservice控制器位于文件夹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 它没有说什么。我无法弄清楚哪个文件是错误的。

1 个答案:

答案 0 :(得分:1)

如果使用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被添加到函数的末尾以检测它是get请求还是post requerst。