我讀過以下主題/教程:Codeigniter RESTful API服務器 - XML錯誤?
- Codeigniter RESTful API Server
- http://code.tutsplus.com/tutorials/working-with-restful-services-in-codeigniter--net-8814
- https://github.com/chriskacerguis/codeigniter-restserver
我仍然想不通爲什麼我的路線問題和XML很問題。 我的web控制器是文件夾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';
我笨的結構文件夾:
> 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 2014-12-05 12:43:10
@克雷格是的。我只是測試,所以我的控制器中沒有其他東西。 – Linesofcode 2014-12-05 13:59:41
我只問,因爲我確信我們之前有過這個問題,這是通過刪除不需要的空白區域來解決的。 – Craig 2014-12-05 14:11:08