我已阅读以下主题/教程:
我仍然无法弄清楚为什么我遇到路由问题和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
我收到以下错误: 它没有说什么。我无法弄清楚哪个文件是错误的。
答案 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。