我正在点击一个API来获取结果,但是我所有的GET请求都返回相同的错误。它还返回我需要的数据。我的API是用Codeigniter编写的。 这是错误:
{
"Error": [
{
"Message": "No matching route for request."
}
]
}{"error":"false","data":[{"id":"7","title":"Interior"},{"id":"8","title":"Exterior"},
{"id":"9","title":"Under
Coat"},{"id":"10","title":"Wood\/Metal"}]}
以下是同一文件的代码:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require APPPATH.'/libraries/REST_Controller.php';
require_once(dirname(__FILE__)."/validation.php");
class Categories extends REST_Controller {
function __construct(){
parent::__construct();
$this->load->model('category_model');
$this->load->database();
$this->load->helper(array('url'));
$this->load->helper('file');
$this->load->library('encrypt');
$this->load->library('session');
$this->load->library('curl');
$this->Validation = new Validation(); //--------------- Called the Validation Class
}
///// Remaping functions to check if the function user is calling exists or not
function _remap($method)
{
$method = $method.'_'.$_SERVER['REQUEST_METHOD'];
if(method_exists($this,$method))
{
call_user_func(array($this, $method));
return false;
}else{
echo '{ "Error": [ { "Message": "No matching route for request." } ] }';
exit;
}
}
// ##################################################################################
// #
// Add / Update Category #
// #
// ##################################################################################
public function index_post()
{
$result = $_POST;
//------------- Name validation
if($this->Validation->is_empty_string($result['title']) == true){
$message = array('Error' => array("Type" => "Error","Code" => "400","Message" => "Category title is missing."));
$jsonMsg = json_encode($message);
//http_response_code(403);
echo $jsonMsg;
exit;
}else{
$title = $result['title'];
}
/*
* If id than update else add
*/
if(isset($result['id']) && $result['id'] != ''){
$id = $result['id'];
$results = $this->category_model->update($id, $title);
}else{
$results = $this->category_model->add($title);
}
if (!empty($results)){
//------------ Sending perameers to Mobile and Web
$message = array('error' => 'false','data'=>$results);
$jsonMsg = json_encode($message);
//http_response_code(202);
echo $jsonMsg;
}else{
$message = array('error' => 'true','data' => 'No record found');
$jsonMsg = json_encode($message);
//http_response_code(403);
echo $jsonMsg;
}
}
// ##################################################################################
// #
// Get Categories #
// #
// ##################################################################################
public function index_get()
{
if(isset($_GET['id']) && $_GET['id'] != ''){
$result = $this->category_model->get($_GET['id']);
$products = $this->category_model->getProductsAgainstCategories($_GET['id']);
$result = array_merge($result[0],$products);
}else{
$result = $this->category_model->get();
}
if (!empty($result)){
//------------ Sending perameers to Mobile and Web
$message = array('error' => 'false', 'data' => $result);
$jsonMsg = json_encode($message);
//http_response_code(202);
echo $jsonMsg;
}else{
$message = array('error' => 'true', "data" => "No record found");
$jsonMsg = json_encode($message);
//http_response_code(403);
echo $jsonMsg;
}
}
// ##################################################################################
// #
// Delete Category #
// #
// ##################################################################################
public function index_delete()
{
if(isset($_GET['id']) && $_GET['id'] != ''){
$result = $this->category_model->delete($_GET['id']);
//------------ Sending perameers to Mobile and Web
$message = array('error' => 'false', 'data' => 'Successfully deleted');
$jsonMsg = json_encode($message);
//http_response_code(202);
echo $jsonMsg;
}else{
$message = array('error' => 'true', "data" => "Nothing to delete");
$jsonMsg = json_encode($message);
//http_response_code(403);
echo $jsonMsg;
}
}
}