【发布时间】:2015-02-03 15:11:28
【问题描述】:
我已阅读以下主题/教程:
- Codeigniter RESTful API Server
- http://code.tutsplus.com/tutorials/working-with-restful-services-in-codeigniter--net-8814
- https://github.com/chriskacerguis/codeigniter-restserver
我仍然无法弄清楚为什么我会遇到路由问题和 XML 问题。
我的网络服务控制器在文件夹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
我收到以下错误: 它没有说别的。我不知道错误在说哪个文件。
【问题讨论】:
-
这是你的完整控制器代码吗?
-
@Craig 是的。我只是在测试,所以我的控制器中没有其他内容。
-
我只是问,因为我确定我们以前遇到过这个问题,已通过删除不需要的空白来解决。
-
我正在尝试删除空行/空格(在文件的头部和底部),看看我是否能找到它
-
@Craig 我已经用这个解决方案github.com/chriskacerguis/codeigniter-restserver/issues/219 解决了 XML 问题,但是路线呢,你知道为什么我需要全部设置吗?
标签: php xml web-services codeigniter rest