Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php “我的Api正在返回错误”;没有匹配的请求路由。”;连同我要求的所有数据_Php_Json_Rest_Api_Codeigniter - Fatal编程技术网

Php “我的Api正在返回错误”;没有匹配的请求路由。”;连同我要求的所有数据

Php “我的Api正在返回错误”;没有匹配的请求路由。”;连同我要求的所有数据,php,json,rest,api,codeigniter,Php,Json,Rest,Api,Codeigniter,我点击一个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

我点击一个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;
            }
    }

}
这是同一文件的代码:

{
"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;
            }
    }

}

API的URL是什么?我知道这是由于_remap函数,REST\u控制器已经检查了路由是否不存在。你只需删除该功能,一切都会正常运行:)@prashant我尝试过这个,但同样的错误我在不同的服务器上有一个相同的项目,但效果很好,我不知道出了什么问题