2016-09-13 43 views
0

这是我的文件夹笨chriskacerguis-RESTAPI未知的访问方法

Controller 
    L>API 
    L>ID 
     L>Example.php 
    L>Example.php 

无论我在API /使用example.php和API/ID /使用example.php使用example.php都像这样一样。

<?php 

defined('BASEPATH') OR exit('No direct script access allowed'); 
require APPPATH . '/core/REST_Controller.php'; 

/** 
* This is an example of a few basic user interaction methods you could use 
* all done with a hardcoded array 
* 
* @package   CodeIgniter 
* @subpackage  Rest Server 
* @category  Controller 
* @author   Phil Sturgeon, Chris Kacerguis 
* @license   MIT 
* @link   https://github.com/chriskacerguis/codeigniter-restserver 
*/ 

class Example extends REST_Controller { 
    public function index_get() 
    { 
     // index from a data store e.g. database 
     $index = [ 
      ['id' => 1, 'name' => 'John', 'email' => '[email protected]', 'fact' => 'Loves coding'], 
      ['id' => 2, 'name' => 'Jim', 'email' => '[email protected]', 'fact' => 'Developed on CodeIgniter'], 
      ['id' => 3, 'name' => 'Jane', 'email' => '[email protected]', 'fact' => 'Lives in the USA', ['hobbies' => ['guitar', 'cycling']]], 
     ]; 

     $id = $this->get('id'); 
     $this->response($index, REST_Controller::HTTP_OK); 
    } 

    public function users_get(){ 
     echo"test";die(); 
    } 
} 

首先,我调整我的config/routes.php文件是这样

$route['API'] = "API"; 
$route['API/(.+)'] = "API/$1"; 

当我访问BASE_URL/API /例/ ID/1它回应了$指数[1]有名叫约翰。

然后,我改变了routes.php文件到

$route["API/example"]="API/ID/example"; 
$route["API/example/(.+)"]="API/ID/example/(.+)"; 

然后我访问我访问BASE_URL/API /例/ ID/1 这将基于routes.php文件 去API/ID /例子,但它回应

{ 
"status": false 
"message": "Unknown method" 
} 

但如果我accesed BASE_URL/API /实例?ID = 1 它报以$指数[1]

如何使用base_url/API/example/id/1 从API/ID/Example.php调用API,它将返回$ index [1]?没有状态:假未知方法

回答

0

我知道解决的办法, 它,因为我的路由是错误的

$route['API/search_location/(.+)']="API/ID/example/index/$1"; 
$route['API/search_location']="API/ID/example";