这是我的文件夹
Controller
L>API
L>ID
L>Example.php
L>Example.php我在API/example.php的example.php和API/ID/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' => 'john@example.com', 'fact' => 'Loves coding'],
['id' => 2, 'name' => 'Jim', 'email' => 'jim@example.com', 'fact' => 'Developed on CodeIgniter'],
['id' => 3, 'name' => 'Jane', 'email' => 'jane@example.com', '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/whoes.php
$route['API'] = "API";
$route['API/(.+)'] = "API/$1";当我访问base_url/API/Example/id/1时,它响应名为John的$index1。
然后我把routes.php改为
$route["API/example"]="API/ID/example";
$route["API/example/(.+)"]="API/ID/example/(.+)";然后我访问了base_url/API/Example/id/1,它将基于routes.php访问API/ID/base,但它的响应
{
"status": false
"message": "Unknown method"
}但是,如果我访问base_url/API/示例?id=1,则它使用$index1响应。
如何使用base_url/ api /样例/id/1从API/id/exprese.php调用API,它将返回$index1?非状态:假未知方法
发布于 2016-09-16 03:24:40
我知道解决办法,因为我的路线是错的。
$route['API/search_location/(.+)']="API/ID/example/index/$1";
$route['API/search_location']="API/ID/example";https://stackoverflow.com/questions/39464238
复制相似问题