我已阅读以下主题/教程:
- Codeigniter RESTful API Server
- http://code.tutsplus.com/tutorials/working-with-restful-services-in-codeigniter--net-8814
- 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
我收到以下错误: 它没有说别的。我无法弄清楚错误所指的是哪个文件。
最佳答案
如果使用 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/